Search in sources :

Example 71 with Calendar

use of com.ibm.icu.util.Calendar in project zm-mailbox by Zimbra.

the class MetadataTest method legacyCalendarItem.

@Test
public void legacyCalendarItem() throws ServiceException, MessagingException {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    SetCalendarItemData defaultInv = new SetCalendarItemData();
    MimeMessage message = new JavaMailMimeMessage(JMSession.getSession(), new ZSharedFileInputStream("data/TestMailRaw/invite1"));
    defaultInv.message = new ParsedMessage(message, Calendar.getInstance().getTimeInMillis(), false);
    TimeZoneMap tzMap = new TimeZoneMap(WellKnownTimeZones.getTimeZoneById("EST"));
    Invite invite = new Invite("REQUEST", tzMap, false);
    invite.setUid("test-uid");
    Calendar cal = GregorianCalendar.getInstance();
    cal.set(2005, 1, 21);
    invite.setDtStart(ParsedDateTime.fromUTCTime(cal.getTimeInMillis()));
    cal.set(2005, 2, 21);
    invite.setDtEnd(ParsedDateTime.fromUTCTime(cal.getTimeInMillis()));
    defaultInv.invite = invite;
    CalendarItem calItem = mbox.setCalendarItem(null, Mailbox.ID_FOLDER_CALENDAR, 0, null, defaultInv, null, null, CalendarItem.NEXT_ALARM_KEEP_CURRENT);
    calItem.mData.dateChanged = (int) (cal.getTimeInMillis() / 1000L);
    Metadata meta = calItem.encodeMetadata();
    meta.remove(Metadata.FN_TZMAP);
    calItem.decodeMetadata(meta);
    Assert.assertEquals(0, calItem.getStartTime());
    Assert.assertEquals(0, calItem.getEndTime());
    // simulate existence of FN_TZMAP with bad content. In reality the metadata versions 4, 5, 6 had more subtle differences in invite encoding, but this provokes the exception we need
    meta.put(Metadata.FN_TZMAP, "foo");
    calItem.decodeMetadata(meta);
    Assert.assertEquals(0, calItem.getStartTime());
    Assert.assertEquals(0, calItem.getEndTime());
    cal.set(2007, 2, 21);
    calItem.mData.dateChanged = (int) (cal.getTimeInMillis() / 1000L);
    boolean caught = false;
    try {
        calItem.decodeMetadata(meta);
    } catch (ServiceException se) {
        if (se.getCode().equalsIgnoreCase(ServiceException.INVALID_REQUEST)) {
            caught = true;
        }
    }
    Assert.assertTrue("new(er) appointment with bad metadata", caught);
}
Also used : ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Calendar(com.ibm.icu.util.Calendar) GregorianCalendar(com.ibm.icu.util.GregorianCalendar) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) SetCalendarItemData(com.zimbra.cs.mailbox.Mailbox.SetCalendarItemData) ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) ServiceException(com.zimbra.common.service.ServiceException) MimeMessage(javax.mail.internet.MimeMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) Invite(com.zimbra.cs.mailbox.calendar.Invite) Test(org.junit.Test)

Example 72 with Calendar

use of com.ibm.icu.util.Calendar in project es6draft by anba.

the class DateTimeFormatObject method createDateFormat.

private DateFormat createDateFormat() {
    ULocale locale = ULocale.forLanguageTag(this.locale);
    // calendar and numberingSystem are already handled in language-tag
    // assert locale.getKeywordValue("calendar").equals(calendar);
    // assert locale.getKeywordValue("numbers").equals(numberingSystem);
    SimpleDateFormat dateFormat = new SimpleDateFormat(pattern.get(), locale);
    if (timeZone != null) {
        dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
    }
    Calendar calendar = dateFormat.getCalendar();
    if (calendar instanceof GregorianCalendar) {
        // format uses a proleptic Gregorian calendar with no year 0
        GregorianCalendar gregorian = (GregorianCalendar) calendar;
        gregorian.setGregorianChange(new Date(Long.MIN_VALUE));
    }
    return dateFormat;
}
Also used : ULocale(com.ibm.icu.util.ULocale) Calendar(com.ibm.icu.util.Calendar) GregorianCalendar(com.ibm.icu.util.GregorianCalendar) GregorianCalendar(com.ibm.icu.util.GregorianCalendar) SimpleDateFormat(com.ibm.icu.text.SimpleDateFormat) Date(java.util.Date)

Example 73 with Calendar

use of com.ibm.icu.util.Calendar in project mycore by MyCoRe-Org.

the class MCRCalendarTest method getDateToFormattedStringForCalendar.

/*
     * Test method for 'org.mycore.datamodel.metadata.MCRCalendar.getJulianDayNumberAsString(Calendar)'
     */
@Test
public void getDateToFormattedStringForCalendar() {
    Calendar calendar;
    String dstring;
    // 15.03.44 BC (julian)
    calendar = MCRCalendar.getHistoryDateAsCalendar("-15.3.44", true, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getCalendarDateToFormattedString(calendar, "dd.MM.yyyy G");
    assertEquals("is not julian date 15.03.44 BC", "15.03.0044 BC", dstring);
    // 15.03.44 BC (gregorian)
    calendar = MCRCalendar.getHistoryDateAsCalendar("-15.3.44", true, MCRCalendar.TAG_GREGORIAN);
    dstring = MCRCalendar.getCalendarDateToFormattedString(calendar, "dd.MM.yyyy G");
    assertEquals("is not gregorian date 15.03.44 BC", "15.03.0044 BC", dstring);
    // 29.02.1700 BC (julian)
    calendar = MCRCalendar.getHistoryDateAsCalendar("29.02.1700", true, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getCalendarDateToFormattedString(calendar, "dd.MM.yyyy G");
    assertEquals("is not julian date 11.03.1700 AD", "11.03.1700 AD", dstring);
    // 29.02.1700 BC (julian)
    calendar = MCRCalendar.getHistoryDateAsCalendar("29.02.1700", true, MCRCalendar.TAG_GREGORIAN);
    dstring = MCRCalendar.getCalendarDateToFormattedString(calendar, "dd.MM.yyyy G");
    assertEquals("is not julian date 01.03.1700 AD", "01.03.1700 AD", dstring);
    // 30.01.800 H. (islamic)
    calendar = MCRCalendar.getHistoryDateAsCalendar("30.1.800 H.", true, MCRCalendar.TAG_ISLAMIC);
    dstring = MCRCalendar.getCalendarDateToFormattedString(calendar, "dd.MM.yyy");
    assertEquals("is not islamic date 30.01.0800 H.", "30.01.800 h.", dstring);
    // 01.01.800 H. (islamic)
    calendar = MCRCalendar.getHistoryDateAsCalendar("1.800 H.", false, MCRCalendar.TAG_ISLAMIC);
    dstring = MCRCalendar.getCalendarDateToFormattedString(calendar, "dd.MM.yyy");
    assertEquals("is not islamic date 01.01.0800 H.", "01.01.800 h.", dstring);
    // 30.01.800 H. (islamic)
    calendar = MCRCalendar.getHistoryDateAsCalendar("1.800 H.", true, MCRCalendar.TAG_ISLAMIC);
    dstring = MCRCalendar.getCalendarDateToFormattedString(calendar, "dd.MM.yyy");
    assertEquals("is not islamic date 30.01.0800 H.", "30.01.800 h.", dstring);
    // 01.01.800 H. (islamic)
    calendar = MCRCalendar.getHistoryDateAsCalendar("800", false, MCRCalendar.TAG_ISLAMIC);
    dstring = MCRCalendar.getCalendarDateToFormattedString(calendar, "dd.MM.yyy");
    assertEquals("is not islamic date 01.01.0800 H.", "01.01.800 h.", dstring);
    // 29.12.800 H. (islamic)
    calendar = MCRCalendar.getHistoryDateAsCalendar("800", true, MCRCalendar.TAG_ISLAMIC);
    dstring = MCRCalendar.getCalendarDateToFormattedString(calendar, "dd.MM.yyy");
    assertEquals("is not islamic date 29.12.0800 H.", "29.12.800 h.", dstring);
    // 29.12.800 H. (islamic)
    calendar = MCRCalendar.getHistoryDateAsCalendar("800 H.", true, MCRCalendar.TAG_ISLAMIC);
    dstring = MCRCalendar.getCalendarDateToFormattedString(calendar, "dd.MM.yyy");
    assertEquals("is not islamic date 29.12.0800 H.", "29.12.800 h.", dstring);
    // 01.01.1724 A.M. (coptic)
    calendar = MCRCalendar.getHistoryDateAsCalendar("1724", false, MCRCalendar.TAG_COPTIC);
    dstring = MCRCalendar.getCalendarDateToFormattedString(calendar, "dd.MM.yyy");
    assertEquals("is not coptic date 01.01.1724 A.M.", "01.01.1724 A.M.", dstring);
    // 01.01.2000 A.M. (ethiopic)
    calendar = MCRCalendar.getHistoryDateAsCalendar("2000", true, MCRCalendar.TAG_ETHIOPIC);
    dstring = MCRCalendar.getCalendarDateToFormattedString(calendar, "dd.MM.yyy");
    assertEquals("is not ethiopic date 05.13.2000 E.E.", "05.13.2000 E.E.", dstring);
}
Also used : Calendar(com.ibm.icu.util.Calendar) GregorianCalendar(com.ibm.icu.util.GregorianCalendar) Test(org.junit.Test)

Example 74 with Calendar

use of com.ibm.icu.util.Calendar in project mycore by MyCoRe-Org.

the class MCRCalendarTest method getHistoryDateAsCalendar.

/*
     * Test method for 'org.mycore.datamodel.metadata.MCRCalendar.getHistoryDateAsCalendar(String, boolean, String)'
     */
@Test
public void getHistoryDateAsCalendar() {
    String cstring, dstring;
    cstring = MCRCalendar.getCalendarDateToFormattedString(new GregorianCalendar());
    Calendar cal;
    // all entries are empty
    try {
        cal = MCRCalendar.getHistoryDateAsCalendar(null, false, null);
    } catch (MCRException e) {
        cal = new GregorianCalendar();
    }
    dstring = MCRCalendar.getCalendarDateToFormattedString(cal);
    assertEquals("Date is not the current date.", cstring, dstring);
    // 0A.01.0001 BC (wrong gregorian)
    try {
        cal = MCRCalendar.getHistoryDateAsCalendar("-0A.01.0001", false, MCRCalendar.TAG_JULIAN);
    } catch (MCRException e) {
        cal = new GregorianCalendar();
    }
    dstring = MCRCalendar.getCalendarDateToFormattedString(cal);
    assertEquals("common", cstring, dstring);
    /* syntax expanding check */
    // 1 (gregorian)
    cal = MCRCalendar.getHistoryDateAsCalendar("1", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("common", "1721424", dstring);
    // 1.1 (gregorian)
    cal = MCRCalendar.getHistoryDateAsCalendar("1.1", true, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("common", "1721454", dstring);
    // 1.1.1 (gregorian)
    cal = MCRCalendar.getHistoryDateAsCalendar("1.1.1", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("common", "1721424", dstring);
    // 1.1.1 QU(gregorian)
    try {
        cal = MCRCalendar.getHistoryDateAsCalendar("1.1.1 QU", false, MCRCalendar.TAG_JULIAN);
    } catch (MCRException e) {
        cal = new GregorianCalendar();
    }
    dstring = MCRCalendar.getCalendarDateToFormattedString(cal);
    assertEquals("common", cstring, dstring);
    // - infinity (julian)
    cal.set(Calendar.JULIAN_DAY, MCRCalendar.MIN_JULIAN_DAY_NUMBER);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 01.01.4713 BC", "0", dstring);
    // + infinity (julian)
    cal.set(Calendar.JULIAN_DAY, MCRCalendar.MAX_JULIAN_DAY_NUMBER);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 28.01.4000 AD", "3182057", dstring);
    // 02.01.4713 BC (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("02.01.4713 bc", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 02.01.4713 BC", "1", dstring);
    // 01.01.0814 BC (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("-814", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 01.01.0814 BC", "1424110", dstring);
    // 01.01.0814 BC (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("-01.01.814", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 01.01.0814 BC", "1424110", dstring);
    // 15.03.0044 BC (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("BC 15.03.44", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 15.03.0044 BC", "1705426", dstring);
    // 01.01.0001 BC (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("01.01.0001 BC", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 01.01.0001 BC", "1721058", dstring);
    // 31.12.0001 BC (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("31.12.0001 v. Chr", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 31.12.0001 BC", "1721423", dstring);
    // 01.01.0000 AD (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("01.01.0000", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 01.01.0000 AD", "1721058", dstring);
    // 01.01.0001 AD (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("01.01.01 AD", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian", "1721424", dstring);
    // 04.10.1582 AD (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("04.10.1582 N. Chr", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 04.10.1582 AD", "2299160", dstring);
    // 05.10.1582 AD (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("05.10.1582", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 05.10.1582 AD", "2299161", dstring);
    // 06.10.1582 AD (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("06.10.1582", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 06.10.1582 AD", "2299162", dstring);
    // 15.10.1582 AD (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("15.10.1582", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 15.10.1582 AD", "2299171", dstring);
    // 16.10.1582 AD (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("16.10.1582", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 16.10.1582 AD", "2299172", dstring);
    // 28.02.1700 AD (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("28.02.1700", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 28.02.1700 AD", "2342041", dstring);
    // 29.02.1700 AD (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("29.02.1700", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 29.02.1700 AD", "2342042", dstring);
    // 01.03.1700 AD (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("01.03.1700", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 01.03.1700 AD", "2342043", dstring);
    // 28.02.1800 AD (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("28.02.1800", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 28.02.1800 AD", "2378566", dstring);
    // 29.02.1800 AD (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("29.02.1800", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 29.02.1800 AD", "2378567", dstring);
    // 01.03.1800 AD (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("01.03.1800", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 01.03.1800 AD", "2378568", dstring);
    // 29.02.1900 AD (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("29.02.1900", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 29.02.1900 AD", "2415092", dstring);
    // 29.02.2100 AD (julian)
    cal = MCRCalendar.getHistoryDateAsCalendar("29.02.2100", false, MCRCalendar.TAG_JULIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("julian: 29.02.2100 AD", "2488142", dstring);
    /* gregorian date check */
    // 04.10.1582 AD (gregorian)
    cal = MCRCalendar.getHistoryDateAsCalendar("04.10.1582", false, MCRCalendar.TAG_GREGORIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("gregorian: 04.10.1582 AD", "2299160", dstring);
    // 05.10.1582 AD (gregorian)
    cal = MCRCalendar.getHistoryDateAsCalendar("05.10.1582", false, MCRCalendar.TAG_GREGORIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("gregorian: 05.10.1582 AD", "2299161", dstring);
    // 15.10.1582 AD (gregorian)
    cal = MCRCalendar.getHistoryDateAsCalendar("15.10.1582", false, MCRCalendar.TAG_GREGORIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("gregorian: 15.10.1582 AD", "2299161", dstring);
    // 06.10.1582 AD (gregorian)
    cal = MCRCalendar.getHistoryDateAsCalendar("16.10.1582", false, MCRCalendar.TAG_GREGORIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("gregorian: 06.10.1582 AD", "2299162", dstring);
    // 31.01.1800 AD (gregorian)
    cal = MCRCalendar.getHistoryDateAsCalendar("1.1800", true, MCRCalendar.TAG_GREGORIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("gregorian: 31.01.1800 AD", "2378527", dstring);
    // 31.01.1800 AD (gregorian)
    cal = MCRCalendar.getHistoryDateAsCalendar("1/1800", true, MCRCalendar.TAG_GREGORIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("gregorian: 31.01.1800 AD", "2378527", dstring);
    // 01.31.1800 AD (gregorian)
    cal = MCRCalendar.getHistoryDateAsCalendar("9/1/1800", true, MCRCalendar.TAG_GREGORIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("gregorian: 01.31.1800 AD", "2378505", dstring);
    // 24.02.1964 AD (gregorian)
    cal = MCRCalendar.getHistoryDateAsCalendar("1964-02-24", true, MCRCalendar.TAG_GREGORIAN);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("gregorian: 1964-02-24 AD", "2438450", dstring);
    // 01.01.0001 h. (islamic)
    cal = MCRCalendar.getHistoryDateAsCalendar("01.01.0001 h.", false, MCRCalendar.TAG_ISLAMIC);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("islamic: 01.01.0001 H.", "1948440", dstring);
    // 01.01.800 H. (islamic)
    cal = MCRCalendar.getHistoryDateAsCalendar("1.800 H.", false, MCRCalendar.TAG_ISLAMIC);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("islamic: 01.01.800 H.", "2231579", dstring);
    // 30.01.800 H. (islamic)
    cal = MCRCalendar.getHistoryDateAsCalendar("1.800 H.", true, MCRCalendar.TAG_ISLAMIC);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("islamic: 30.01.800 H.", "2231608", dstring);
    // 29.12.800 H. (islamic)
    cal = MCRCalendar.getHistoryDateAsCalendar("800", true, MCRCalendar.TAG_ISLAMIC);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("islamic: 29.12.800 H.", "2231932", dstring);
    // 01.01.0001 A.M. (coptioc)
    cal = MCRCalendar.getHistoryDateAsCalendar("1.1.1 a.M.", false, MCRCalendar.TAG_COPTIC);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("coptic: 01.01.0001 A.M.", "1825030", dstring);
    // 01.01.1724 A.M. (coptioc)
    cal = MCRCalendar.getHistoryDateAsCalendar("1.1.1724 A.M.", false, MCRCalendar.TAG_COPTIC);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("coptic: 01.01.1724 A.M.", "2454356", dstring);
    // 05.13.1724 E.E. (coptic)
    cal = MCRCalendar.getHistoryDateAsCalendar("1724 a.M.", true, MCRCalendar.TAG_COPTIC);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("coptic: 05.13.2000 E.E.", "2454720", dstring);
    // 01.01.0001 E.E. (ethiopic)
    cal = MCRCalendar.getHistoryDateAsCalendar("1 E.E.", false, MCRCalendar.TAG_ETHIOPIC);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("coptic: 01.01.0001 E.E.", "1724221", dstring);
    // 05.13.2000 E.E. (ethiopic)
    cal = MCRCalendar.getHistoryDateAsCalendar("2000 E.E.", true, MCRCalendar.TAG_ETHIOPIC);
    dstring = MCRCalendar.getJulianDayNumberAsString(cal);
    assertEquals("coptic: 05.13.2000 E.E.", "2454720", dstring);
}
Also used : Calendar(com.ibm.icu.util.Calendar) GregorianCalendar(com.ibm.icu.util.GregorianCalendar) GregorianCalendar(com.ibm.icu.util.GregorianCalendar) Test(org.junit.Test)

Example 75 with Calendar

use of com.ibm.icu.util.Calendar in project mycore by MyCoRe-Org.

the class MCRMetaHistoryDate method validate.

/**
 * Validates this MCRMetaHistoryDate. This method throws an exception if:
 * <ul>
 * <li>the subtag is not null or empty</li>
 * <li>the lang value was supported</li>
 * <li>the inherited value is lower than zero</li>
 * <li>the number of texts is 0 (empty texts are delete)</li>
 * <li>von is null or bis is null or calendar is null</li>
 * </ul>
 *
 * @throws MCRException the MCRMetaHistoryDate is invalid
 */
@Override
public void validate() throws MCRException {
    super.validate();
    for (int i = 0; i < texts.size(); i++) {
        MCRMetaHistoryDateText textitem = texts.get(i);
        if (!textitem.isValid()) {
            texts.remove(i);
            i--;
        }
    }
    if (texts.size() == 0) {
        throw new MCRException(getSubTag() + ": no texts defined");
    }
    if (von == null || bis == null || calendar == null) {
        throw new MCRException(getSubTag() + ": von,bis or calendar are null");
    }
    if (ibis < ivon) {
        Calendar swp = (Calendar) von.clone();
        setVonDate((Calendar) bis.clone());
        setBisDate(swp);
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRCalendar(org.mycore.common.MCRCalendar) Calendar(com.ibm.icu.util.Calendar) GregorianCalendar(com.ibm.icu.util.GregorianCalendar)

Aggregations

Calendar (com.ibm.icu.util.Calendar)75 Timestamp (java.sql.Timestamp)37 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)24 GenericValue (org.apache.ofbiz.entity.GenericValue)24 Delegator (org.apache.ofbiz.entity.Delegator)17 Date (java.util.Date)14 HashMap (java.util.HashMap)12 Locale (java.util.Locale)12 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)11 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)11 GregorianCalendar (com.ibm.icu.util.GregorianCalendar)10 ArrayList (java.util.ArrayList)8 SimpleDateFormat (java.text.SimpleDateFormat)6 LinkedList (java.util.LinkedList)6 EntityCondition (org.apache.ofbiz.entity.condition.EntityCondition)6 Map (java.util.Map)5 TimeDuration (org.apache.ofbiz.base.util.TimeDuration)5 BigDecimal (java.math.BigDecimal)4 Time (java.sql.Time)4 UtilDateTime (org.apache.ofbiz.base.util.UtilDateTime)4