org.joda.time.DateTimeField#get ( )源码实例Demo

下面列出了org.joda.time.DateTimeField#get ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: astor   文件: TestBuddhistChronology.java
public void testCalendar() {
    if (TestAll.FAST) {
        return;
    }
    System.out.println("\nTestBuddhistChronology.testCalendar");
    DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, BUDDHIST_UTC);
    long millis = epoch.getMillis();
    long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis();
    DateTimeField dayOfWeek = BUDDHIST_UTC.dayOfWeek();
    DateTimeField weekOfWeekyear = GJ_UTC.weekOfWeekyear();
    DateTimeField dayOfYear = BUDDHIST_UTC.dayOfYear();
    DateTimeField dayOfMonth = BUDDHIST_UTC.dayOfMonth();
    DateTimeField monthOfYear = BUDDHIST_UTC.monthOfYear();
    DateTimeField year = BUDDHIST_UTC.year();
    DateTimeField yearOfEra = BUDDHIST_UTC.yearOfEra();
    DateTimeField era = BUDDHIST_UTC.era();
    DateTimeField gjDayOfWeek = GJ_UTC.dayOfWeek();
    DateTimeField gjWeekOfWeekyear = GJ_UTC.weekOfWeekyear();
    DateTimeField gjDayOfYear = GJ_UTC.dayOfYear();
    DateTimeField gjDayOfMonth = GJ_UTC.dayOfMonth();
    DateTimeField gjMonthOfYear = GJ_UTC.monthOfYear();
    DateTimeField gjYear = GJ_UTC.year();
    while (millis < end) {
        assertEquals(gjDayOfWeek.get(millis), dayOfWeek.get(millis));
        assertEquals(gjDayOfYear.get(millis), dayOfYear.get(millis));
        assertEquals(gjDayOfMonth.get(millis), dayOfMonth.get(millis));
        assertEquals(gjMonthOfYear.get(millis), monthOfYear.get(millis));
        assertEquals(gjWeekOfWeekyear.get(millis), weekOfWeekyear.get(millis));
        assertEquals(1, era.get(millis));
        int yearValue = gjYear.get(millis);
        if (yearValue <= 0) {
            yearValue++;
        }
        yearValue += 543;
        assertEquals(yearValue, year.get(millis));
        assertEquals(yearValue, yearOfEra.get(millis));
        millis += SKIP;
    }
}
 
源代码2 项目: coming   文件: Time_11_ZoneInfoCompiler_s.java
static int parseMonth(String str) {
    DateTimeField field = ISOChronology.getInstanceUTC().monthOfYear();
    return field.get(field.set(0, str, Locale.ENGLISH));
}
 
源代码3 项目: coming   文件: Time_11_ZoneInfoCompiler_s.java
static int parseDayOfWeek(String str) {
    DateTimeField field = ISOChronology.getInstanceUTC().dayOfWeek();
    return field.get(field.set(0, str, Locale.ENGLISH));
}
 
源代码4 项目: coming   文件: Time_11_ZoneInfoCompiler_t.java
static int parseMonth(String str) {
    DateTimeField field = ISOChronology.getInstanceUTC().monthOfYear();
    return field.get(field.set(0, str, Locale.ENGLISH));
}
 
源代码5 项目: coming   文件: Time_11_ZoneInfoCompiler_t.java
static int parseDayOfWeek(String str) {
    DateTimeField field = ISOChronology.getInstanceUTC().dayOfWeek();
    return field.get(field.set(0, str, Locale.ENGLISH));
}
 
源代码6 项目: astor   文件: ZoneInfoCompiler.java
static int parseMonth(String str) {
    DateTimeField field = ISOChronology.getInstanceUTC().monthOfYear();
    return field.get(field.set(0, str, Locale.ENGLISH));
}
 
源代码7 项目: astor   文件: ZoneInfoCompiler.java
static int parseDayOfWeek(String str) {
    DateTimeField field = ISOChronology.getInstanceUTC().dayOfWeek();
    return field.get(field.set(0, str, Locale.ENGLISH));
}
 
源代码8 项目: astor   文件: MainTest.java
private void testField(DateTimeField fieldA, DateTimeField fieldB, long millis,
                       int value, long millis2)
{
    int a, b;
    long x, y;
    boolean m, n;

    // get test
    a = fieldA.get(millis);
    b = fieldB.get(millis);
    testValue(fieldA, fieldB, "get", millis, a, b);

    // getMaximumValue test
    // Restrict this test to the fields that matter.
    Class fieldClass = fieldA.getClass();
    if (fieldClass == TestGJDayOfYearField.class ||
        fieldClass == TestGJDayOfMonthField.class ||
        fieldClass == TestGJWeekOfWeekyearField.class) {
        
        a = fieldA.getMaximumValue(millis);
        b = fieldB.getMaximumValue(millis);
        testValue(fieldA, fieldB, "getMaximumValue", millis, a, b);
    }

    // set test
    a = getWrappedValue
        (value, fieldA.getMinimumValue(millis), fieldA.getMaximumValue(millis));
    b = getWrappedValue
        (value, fieldB.getMinimumValue(millis), fieldB.getMaximumValue(millis));
    if (iMode == JULIAN_MODE && a == 0
        && (fieldA.getName().equals("year") || fieldA.getName().equals("weekyear"))) {
        // Exclude setting Julian year of zero.
    } else {
        x = fieldA.set(millis, a);
        y = fieldB.set(millis, b);
        testMillis(fieldA, fieldB, "set", millis, x, y, a, b);
    }

    // roundFloor test
    x = fieldA.roundFloor(millis);
    y = fieldB.roundFloor(millis);
    testMillis(fieldA, fieldB, "roundFloor", millis, x, y);

    // roundCeiling test
    x = fieldA.roundCeiling(millis);
    y = fieldB.roundCeiling(millis);
    testMillis(fieldA, fieldB, "roundCeiling", millis, x, y);

    // roundHalfFloor test
    x = fieldA.roundHalfFloor(millis);
    y = fieldB.roundHalfFloor(millis);
    testMillis(fieldA, fieldB, "roundHalfFloor", millis, x, y);

    // roundHalfEven test
    x = fieldA.roundHalfEven(millis);
    y = fieldB.roundHalfEven(millis);
    testMillis(fieldA, fieldB, "roundHalfEven", millis, x, y);

    // remainder test
    x = fieldA.remainder(millis);
    y = fieldB.remainder(millis);
    testMillis(fieldA, fieldB, "remainder", millis, x, y);

    // add test
    x = fieldA.add(millis, value);
    y = fieldB.add(millis, value);
    testMillis(fieldA, fieldB, "add", millis, x, y);

    // addWrapField test
    x = fieldA.addWrapField(millis, value);
    y = fieldB.addWrapField(millis, value);
    testMillis(fieldA, fieldB, "addWrapField", millis, x, y);

    // getDifference test
    x = fieldA.getDifference(millis, millis2);
    y = fieldB.getDifference(millis, millis2);
    try {
        testValue(fieldA, fieldB, "getDifference", millis, x, y);
    } catch (RuntimeException e) {
        System.out.println("Test datetime 2: " + makeDatetime(millis2));
        throw e;
    }

    // isLeap test
    m = fieldA.isLeap(millis);
    n = fieldB.isLeap(millis);
    testBoolean(fieldA, fieldB, "isLeap", millis, m, n);

    // getLeapAmount test
    a = fieldA.getLeapAmount(millis);
    b = fieldB.getLeapAmount(millis);
    testValue(fieldA, fieldB, "getLeapAmount", millis, a, b);
}
 
源代码9 项目: astor   文件: TestIslamicChronology.java
/**
 * Tests era, year, monthOfYear, dayOfMonth and dayOfWeek.
 */
public void testCalendar() {
    if (TestAll.FAST) {
        return;
    }
    System.out.println("\nTestIslamicChronology.testCalendar");
    DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, ISLAMIC_UTC);
    long millis = epoch.getMillis();
    long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis();
    DateTimeField dayOfWeek = ISLAMIC_UTC.dayOfWeek();
    DateTimeField dayOfYear = ISLAMIC_UTC.dayOfYear();
    DateTimeField dayOfMonth = ISLAMIC_UTC.dayOfMonth();
    DateTimeField monthOfYear = ISLAMIC_UTC.monthOfYear();
    DateTimeField year = ISLAMIC_UTC.year();
    DateTimeField yearOfEra = ISLAMIC_UTC.yearOfEra();
    DateTimeField era = ISLAMIC_UTC.era();
    int expectedDOW = new DateTime(622, 7, 16, 0, 0, 0, 0, JULIAN_UTC).getDayOfWeek();
    int expectedDOY = 1;
    int expectedDay = 1;
    int expectedMonth = 1;
    int expectedYear = 1;
    while (millis < end) {
        int dowValue = dayOfWeek.get(millis);
        int doyValue = dayOfYear.get(millis);
        int dayValue = dayOfMonth.get(millis);
        int monthValue = monthOfYear.get(millis);
        int yearValue = year.get(millis);
        int yearOfEraValue = yearOfEra.get(millis);
        int dayOfYearLen = dayOfYear.getMaximumValue(millis);
        int monthLen = dayOfMonth.getMaximumValue(millis);
        if (monthValue < 1 || monthValue > 12) {
            fail("Bad month: " + millis);
        }
        
        // test era
        assertEquals(1, era.get(millis));
        assertEquals("AH", era.getAsText(millis));
        assertEquals("AH", era.getAsShortText(millis));
        
        // test date
        assertEquals(expectedDOY, doyValue);
        assertEquals(expectedMonth, monthValue);
        assertEquals(expectedDay, dayValue);
        assertEquals(expectedDOW, dowValue);
        assertEquals(expectedYear, yearValue);
        assertEquals(expectedYear, yearOfEraValue);
        
        // test leap year
        boolean leap = ((11 * yearValue + 14) % 30) < 11;
        assertEquals(leap, year.isLeap(millis));
        
        // test month length
        switch (monthValue) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 9:
            case 11:
                assertEquals(30, monthLen);
                break;
            case 2:
            case 4:
            case 6:
            case 8:
            case 10:
                assertEquals(29, monthLen);
                break;
            case 12:
                assertEquals((leap ? 30 : 29), monthLen);
                break;
        }
        
        // test year length
        assertEquals((leap ? 355 : 354), dayOfYearLen);
        
        // recalculate date
        expectedDOW = (((expectedDOW + 1) - 1) % 7) + 1;
        expectedDay++;
        expectedDOY++;
        if (expectedDay > monthLen) {
            expectedDay = 1;
            expectedMonth++;
            if (expectedMonth == 13) {
                expectedMonth = 1;
                expectedDOY = 1;
                expectedYear++;
            }
        }
        millis += SKIP;
    }
}
 
源代码10 项目: astor   文件: TestCopticChronology.java
/**
 * Tests era, year, monthOfYear, dayOfMonth and dayOfWeek.
 */
public void testCalendar() {
    if (TestAll.FAST) {
        return;
    }
    System.out.println("\nTestCopticChronology.testCalendar");
    DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, COPTIC_UTC);
    long millis = epoch.getMillis();
    long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis();
    DateTimeField dayOfWeek = COPTIC_UTC.dayOfWeek();
    DateTimeField dayOfYear = COPTIC_UTC.dayOfYear();
    DateTimeField dayOfMonth = COPTIC_UTC.dayOfMonth();
    DateTimeField monthOfYear = COPTIC_UTC.monthOfYear();
    DateTimeField year = COPTIC_UTC.year();
    DateTimeField yearOfEra = COPTIC_UTC.yearOfEra();
    DateTimeField era = COPTIC_UTC.era();
    int expectedDOW = new DateTime(284, 8, 29, 0, 0, 0, 0, JULIAN_UTC).getDayOfWeek();
    int expectedDOY = 1;
    int expectedDay = 1;
    int expectedMonth = 1;
    int expectedYear = 1;
    while (millis < end) {
        int dowValue = dayOfWeek.get(millis);
        int doyValue = dayOfYear.get(millis);
        int dayValue = dayOfMonth.get(millis);
        int monthValue = monthOfYear.get(millis);
        int yearValue = year.get(millis);
        int yearOfEraValue = yearOfEra.get(millis);
        int monthLen = dayOfMonth.getMaximumValue(millis);
        if (monthValue < 1 || monthValue > 13) {
            fail("Bad month: " + millis);
        }
        
        // test era
        assertEquals(1, era.get(millis));
        assertEquals("AM", era.getAsText(millis));
        assertEquals("AM", era.getAsShortText(millis));
        
        // test date
        assertEquals(expectedYear, yearValue);
        assertEquals(expectedYear, yearOfEraValue);
        assertEquals(expectedMonth, monthValue);
        assertEquals(expectedDay, dayValue);
        assertEquals(expectedDOW, dowValue);
        assertEquals(expectedDOY, doyValue);
        
        // test leap year
        assertEquals(yearValue % 4 == 3, year.isLeap(millis));
        
        // test month length
        if (monthValue == 13) {
            assertEquals(yearValue % 4 == 3, monthOfYear.isLeap(millis));
            if (yearValue % 4 == 3) {
                assertEquals(6, monthLen);
            } else {
                assertEquals(5, monthLen);
            }
        } else {
            assertEquals(30, monthLen);
        }
        
        // recalculate date
        expectedDOW = (((expectedDOW + 1) - 1) % 7) + 1;
        expectedDay++;
        expectedDOY++;
        if (expectedDay == 31 && expectedMonth < 13) {
            expectedDay = 1;
            expectedMonth++;
        } else if (expectedMonth == 13) {
            if (expectedYear % 4 == 3 && expectedDay == 7) {
                expectedDay = 1;
                expectedMonth = 1;
                expectedYear++;
                expectedDOY = 1;
            } else if (expectedYear % 4 != 3 && expectedDay == 6) {
                expectedDay = 1;
                expectedMonth = 1;
                expectedYear++;
                expectedDOY = 1;
            }
        }
        millis += SKIP;
    }
}
 
源代码11 项目: astor   文件: TestEthiopicChronology.java
/**
 * Tests era, year, monthOfYear, dayOfMonth and dayOfWeek.
 */
public void testCalendar() {
    if (TestAll.FAST) {
        return;
    }
    System.out.println("\nTestEthiopicChronology.testCalendar");
    DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, ETHIOPIC_UTC);
    long millis = epoch.getMillis();
    long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis();
    DateTimeField dayOfWeek = ETHIOPIC_UTC.dayOfWeek();
    DateTimeField dayOfYear = ETHIOPIC_UTC.dayOfYear();
    DateTimeField dayOfMonth = ETHIOPIC_UTC.dayOfMonth();
    DateTimeField monthOfYear = ETHIOPIC_UTC.monthOfYear();
    DateTimeField year = ETHIOPIC_UTC.year();
    DateTimeField yearOfEra = ETHIOPIC_UTC.yearOfEra();
    DateTimeField era = ETHIOPIC_UTC.era();
    int expectedDOW = new DateTime(8, 8, 29, 0, 0, 0, 0, JULIAN_UTC).getDayOfWeek();
    int expectedDOY = 1;
    int expectedDay = 1;
    int expectedMonth = 1;
    int expectedYear = 1;
    while (millis < end) {
        int dowValue = dayOfWeek.get(millis);
        int doyValue = dayOfYear.get(millis);
        int dayValue = dayOfMonth.get(millis);
        int monthValue = monthOfYear.get(millis);
        int yearValue = year.get(millis);
        int yearOfEraValue = yearOfEra.get(millis);
        int monthLen = dayOfMonth.getMaximumValue(millis);
        if (monthValue < 1 || monthValue > 13) {
            fail("Bad month: " + millis);
        }
        
        // test era
        assertEquals(1, era.get(millis));
        assertEquals("EE", era.getAsText(millis));
        assertEquals("EE", era.getAsShortText(millis));
        
        // test date
        assertEquals(expectedYear, yearValue);
        assertEquals(expectedYear, yearOfEraValue);
        assertEquals(expectedMonth, monthValue);
        assertEquals(expectedDay, dayValue);
        assertEquals(expectedDOW, dowValue);
        assertEquals(expectedDOY, doyValue);
        
        // test leap year
        assertEquals(yearValue % 4 == 3, year.isLeap(millis));
        
        // test month length
        if (monthValue == 13) {
            assertEquals(yearValue % 4 == 3, monthOfYear.isLeap(millis));
            if (yearValue % 4 == 3) {
                assertEquals(6, monthLen);
            } else {
                assertEquals(5, monthLen);
            }
        } else {
            assertEquals(30, monthLen);
        }
        
        // recalculate date
        expectedDOW = (((expectedDOW + 1) - 1) % 7) + 1;
        expectedDay++;
        expectedDOY++;
        if (expectedDay == 31 && expectedMonth < 13) {
            expectedDay = 1;
            expectedMonth++;
        } else if (expectedMonth == 13) {
            if (expectedYear % 4 == 3 && expectedDay == 7) {
                expectedDay = 1;
                expectedMonth = 1;
                expectedYear++;
                expectedDOY = 1;
            } else if (expectedYear % 4 != 3 && expectedDay == 6) {
                expectedDay = 1;
                expectedMonth = 1;
                expectedYear++;
                expectedDOY = 1;
            }
        }
        millis += SKIP;
    }
}
 
源代码12 项目: astor   文件: ZoneInfoCompiler.java
static int parseMonth(String str) {
    DateTimeField field = ISOChronology.getInstanceUTC().monthOfYear();
    return field.get(field.set(0, str, Locale.ENGLISH));
}
 
源代码13 项目: astor   文件: ZoneInfoCompiler.java
static int parseDayOfWeek(String str) {
    DateTimeField field = ISOChronology.getInstanceUTC().dayOfWeek();
    return field.get(field.set(0, str, Locale.ENGLISH));
}
 
源代码14 项目: astor   文件: MainTest.java
private void testField(DateTimeField fieldA, DateTimeField fieldB, long millis,
                       int value, long millis2)
{
    int a, b;
    long x, y;
    boolean m, n;

    // get test
    a = fieldA.get(millis);
    b = fieldB.get(millis);
    testValue(fieldA, fieldB, "get", millis, a, b);

    // getMaximumValue test
    // Restrict this test to the fields that matter.
    Class fieldClass = fieldA.getClass();
    if (fieldClass == TestGJDayOfYearField.class ||
        fieldClass == TestGJDayOfMonthField.class ||
        fieldClass == TestGJWeekOfWeekyearField.class) {
        
        a = fieldA.getMaximumValue(millis);
        b = fieldB.getMaximumValue(millis);
        testValue(fieldA, fieldB, "getMaximumValue", millis, a, b);
    }

    // set test
    a = getWrappedValue
        (value, fieldA.getMinimumValue(millis), fieldA.getMaximumValue(millis));
    b = getWrappedValue
        (value, fieldB.getMinimumValue(millis), fieldB.getMaximumValue(millis));
    if (iMode == JULIAN_MODE && a == 0
        && (fieldA.getName().equals("year") || fieldA.getName().equals("weekyear"))) {
        // Exclude setting Julian year of zero.
    } else {
        x = fieldA.set(millis, a);
        y = fieldB.set(millis, b);
        testMillis(fieldA, fieldB, "set", millis, x, y, a, b);
    }

    // roundFloor test
    x = fieldA.roundFloor(millis);
    y = fieldB.roundFloor(millis);
    testMillis(fieldA, fieldB, "roundFloor", millis, x, y);

    // roundCeiling test
    x = fieldA.roundCeiling(millis);
    y = fieldB.roundCeiling(millis);
    testMillis(fieldA, fieldB, "roundCeiling", millis, x, y);

    // roundHalfFloor test
    x = fieldA.roundHalfFloor(millis);
    y = fieldB.roundHalfFloor(millis);
    testMillis(fieldA, fieldB, "roundHalfFloor", millis, x, y);

    // roundHalfEven test
    x = fieldA.roundHalfEven(millis);
    y = fieldB.roundHalfEven(millis);
    testMillis(fieldA, fieldB, "roundHalfEven", millis, x, y);

    // remainder test
    x = fieldA.remainder(millis);
    y = fieldB.remainder(millis);
    testMillis(fieldA, fieldB, "remainder", millis, x, y);

    // add test
    x = fieldA.add(millis, value);
    y = fieldB.add(millis, value);
    testMillis(fieldA, fieldB, "add", millis, x, y);

    // addWrapField test
    x = fieldA.addWrapField(millis, value);
    y = fieldB.addWrapField(millis, value);
    testMillis(fieldA, fieldB, "addWrapField", millis, x, y);

    // getDifference test
    x = fieldA.getDifference(millis, millis2);
    y = fieldB.getDifference(millis, millis2);
    try {
        testValue(fieldA, fieldB, "getDifference", millis, x, y);
    } catch (RuntimeException e) {
        System.out.println("Test datetime 2: " + makeDatetime(millis2));
        throw e;
    }

    // isLeap test
    m = fieldA.isLeap(millis);
    n = fieldB.isLeap(millis);
    testBoolean(fieldA, fieldB, "isLeap", millis, m, n);

    // getLeapAmount test
    a = fieldA.getLeapAmount(millis);
    b = fieldB.getLeapAmount(millis);
    testValue(fieldA, fieldB, "getLeapAmount", millis, a, b);
}
 
源代码15 项目: astor   文件: TestIslamicChronology.java
/**
 * Tests era, year, monthOfYear, dayOfMonth and dayOfWeek.
 */
public void testCalendar() {
    if (TestAll.FAST) {
        return;
    }
    System.out.println("\nTestIslamicChronology.testCalendar");
    DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, ISLAMIC_UTC);
    long millis = epoch.getMillis();
    long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis();
    DateTimeField dayOfWeek = ISLAMIC_UTC.dayOfWeek();
    DateTimeField dayOfYear = ISLAMIC_UTC.dayOfYear();
    DateTimeField dayOfMonth = ISLAMIC_UTC.dayOfMonth();
    DateTimeField monthOfYear = ISLAMIC_UTC.monthOfYear();
    DateTimeField year = ISLAMIC_UTC.year();
    DateTimeField yearOfEra = ISLAMIC_UTC.yearOfEra();
    DateTimeField era = ISLAMIC_UTC.era();
    int expectedDOW = new DateTime(622, 7, 16, 0, 0, 0, 0, JULIAN_UTC).getDayOfWeek();
    int expectedDOY = 1;
    int expectedDay = 1;
    int expectedMonth = 1;
    int expectedYear = 1;
    while (millis < end) {
        int dowValue = dayOfWeek.get(millis);
        int doyValue = dayOfYear.get(millis);
        int dayValue = dayOfMonth.get(millis);
        int monthValue = monthOfYear.get(millis);
        int yearValue = year.get(millis);
        int yearOfEraValue = yearOfEra.get(millis);
        int dayOfYearLen = dayOfYear.getMaximumValue(millis);
        int monthLen = dayOfMonth.getMaximumValue(millis);
        if (monthValue < 1 || monthValue > 12) {
            fail("Bad month: " + millis);
        }
        
        // test era
        assertEquals(1, era.get(millis));
        assertEquals("AH", era.getAsText(millis));
        assertEquals("AH", era.getAsShortText(millis));
        
        // test date
        assertEquals(expectedDOY, doyValue);
        assertEquals(expectedMonth, monthValue);
        assertEquals(expectedDay, dayValue);
        assertEquals(expectedDOW, dowValue);
        assertEquals(expectedYear, yearValue);
        assertEquals(expectedYear, yearOfEraValue);
        
        // test leap year
        boolean leap = ((11 * yearValue + 14) % 30) < 11;
        assertEquals(leap, year.isLeap(millis));
        
        // test month length
        switch (monthValue) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 9:
            case 11:
                assertEquals(30, monthLen);
                break;
            case 2:
            case 4:
            case 6:
            case 8:
            case 10:
                assertEquals(29, monthLen);
                break;
            case 12:
                assertEquals((leap ? 30 : 29), monthLen);
                break;
        }
        
        // test year length
        assertEquals((leap ? 355 : 354), dayOfYearLen);
        
        // recalculate date
        expectedDOW = (((expectedDOW + 1) - 1) % 7) + 1;
        expectedDay++;
        expectedDOY++;
        if (expectedDay > monthLen) {
            expectedDay = 1;
            expectedMonth++;
            if (expectedMonth == 13) {
                expectedMonth = 1;
                expectedDOY = 1;
                expectedYear++;
            }
        }
        millis += SKIP;
    }
}
 
源代码16 项目: astor   文件: TestBuddhistChronology.java
public void testCalendar() {
    if (TestAll.FAST) {
        return;
    }
    System.out.println("\nTestBuddhistChronology.testCalendar");
    DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, BUDDHIST_UTC);
    long millis = epoch.getMillis();
    long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis();
    DateTimeField dayOfWeek = BUDDHIST_UTC.dayOfWeek();
    DateTimeField weekOfWeekyear = GJ_UTC.weekOfWeekyear();
    DateTimeField dayOfYear = BUDDHIST_UTC.dayOfYear();
    DateTimeField dayOfMonth = BUDDHIST_UTC.dayOfMonth();
    DateTimeField monthOfYear = BUDDHIST_UTC.monthOfYear();
    DateTimeField year = BUDDHIST_UTC.year();
    DateTimeField yearOfEra = BUDDHIST_UTC.yearOfEra();
    DateTimeField era = BUDDHIST_UTC.era();
    DateTimeField gjDayOfWeek = GJ_UTC.dayOfWeek();
    DateTimeField gjWeekOfWeekyear = GJ_UTC.weekOfWeekyear();
    DateTimeField gjDayOfYear = GJ_UTC.dayOfYear();
    DateTimeField gjDayOfMonth = GJ_UTC.dayOfMonth();
    DateTimeField gjMonthOfYear = GJ_UTC.monthOfYear();
    DateTimeField gjYear = GJ_UTC.year();
    DateTimeField gjYearOfEra = GJ_UTC.yearOfEra();
    DateTimeField gjEra = GJ_UTC.era();
    while (millis < end) {
        assertEquals(gjDayOfWeek.get(millis), dayOfWeek.get(millis));
        assertEquals(gjDayOfYear.get(millis), dayOfYear.get(millis));
        assertEquals(gjDayOfMonth.get(millis), dayOfMonth.get(millis));
        assertEquals(gjMonthOfYear.get(millis), monthOfYear.get(millis));
        assertEquals(gjWeekOfWeekyear.get(millis), weekOfWeekyear.get(millis));
        assertEquals(1, era.get(millis));
        int yearValue = gjYear.get(millis);
        if (yearValue <= 0) {
            yearValue++;
        }
        yearValue += 543;
        assertEquals(yearValue, year.get(millis));
        assertEquals(yearValue, yearOfEra.get(millis));
        millis += SKIP;
    }
}
 
源代码17 项目: astor   文件: TestCopticChronology.java
/**
 * Tests era, year, monthOfYear, dayOfMonth and dayOfWeek.
 */
public void testCalendar() {
    if (TestAll.FAST) {
        return;
    }
    System.out.println("\nTestCopticChronology.testCalendar");
    DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, COPTIC_UTC);
    long millis = epoch.getMillis();
    long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis();
    DateTimeField dayOfWeek = COPTIC_UTC.dayOfWeek();
    DateTimeField dayOfYear = COPTIC_UTC.dayOfYear();
    DateTimeField dayOfMonth = COPTIC_UTC.dayOfMonth();
    DateTimeField monthOfYear = COPTIC_UTC.monthOfYear();
    DateTimeField year = COPTIC_UTC.year();
    DateTimeField yearOfEra = COPTIC_UTC.yearOfEra();
    DateTimeField era = COPTIC_UTC.era();
    int expectedDOW = new DateTime(284, 8, 29, 0, 0, 0, 0, JULIAN_UTC).getDayOfWeek();
    int expectedDOY = 1;
    int expectedDay = 1;
    int expectedMonth = 1;
    int expectedYear = 1;
    while (millis < end) {
        int dowValue = dayOfWeek.get(millis);
        int doyValue = dayOfYear.get(millis);
        int dayValue = dayOfMonth.get(millis);
        int monthValue = monthOfYear.get(millis);
        int yearValue = year.get(millis);
        int yearOfEraValue = yearOfEra.get(millis);
        int monthLen = dayOfMonth.getMaximumValue(millis);
        if (monthValue < 1 || monthValue > 13) {
            fail("Bad month: " + millis);
        }
        
        // test era
        assertEquals(1, era.get(millis));
        assertEquals("AM", era.getAsText(millis));
        assertEquals("AM", era.getAsShortText(millis));
        
        // test date
        assertEquals(expectedYear, yearValue);
        assertEquals(expectedYear, yearOfEraValue);
        assertEquals(expectedMonth, monthValue);
        assertEquals(expectedDay, dayValue);
        assertEquals(expectedDOW, dowValue);
        assertEquals(expectedDOY, doyValue);
        
        // test leap year
        assertEquals(yearValue % 4 == 3, year.isLeap(millis));
        
        // test month length
        if (monthValue == 13) {
            assertEquals(yearValue % 4 == 3, monthOfYear.isLeap(millis));
            if (yearValue % 4 == 3) {
                assertEquals(6, monthLen);
            } else {
                assertEquals(5, monthLen);
            }
        } else {
            assertEquals(30, monthLen);
        }
        
        // recalculate date
        expectedDOW = (((expectedDOW + 1) - 1) % 7) + 1;
        expectedDay++;
        expectedDOY++;
        if (expectedDay == 31 && expectedMonth < 13) {
            expectedDay = 1;
            expectedMonth++;
        } else if (expectedMonth == 13) {
            if (expectedYear % 4 == 3 && expectedDay == 7) {
                expectedDay = 1;
                expectedMonth = 1;
                expectedYear++;
                expectedDOY = 1;
            } else if (expectedYear % 4 != 3 && expectedDay == 6) {
                expectedDay = 1;
                expectedMonth = 1;
                expectedYear++;
                expectedDOY = 1;
            }
        }
        millis += SKIP;
    }
}
 
源代码18 项目: astor   文件: TestEthiopicChronology.java
/**
 * Tests era, year, monthOfYear, dayOfMonth and dayOfWeek.
 */
public void testCalendar() {
    if (TestAll.FAST) {
        return;
    }
    System.out.println("\nTestEthiopicChronology.testCalendar");
    DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, ETHIOPIC_UTC);
    long millis = epoch.getMillis();
    long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis();
    DateTimeField dayOfWeek = ETHIOPIC_UTC.dayOfWeek();
    DateTimeField dayOfYear = ETHIOPIC_UTC.dayOfYear();
    DateTimeField dayOfMonth = ETHIOPIC_UTC.dayOfMonth();
    DateTimeField monthOfYear = ETHIOPIC_UTC.monthOfYear();
    DateTimeField year = ETHIOPIC_UTC.year();
    DateTimeField yearOfEra = ETHIOPIC_UTC.yearOfEra();
    DateTimeField era = ETHIOPIC_UTC.era();
    int expectedDOW = new DateTime(8, 8, 29, 0, 0, 0, 0, JULIAN_UTC).getDayOfWeek();
    int expectedDOY = 1;
    int expectedDay = 1;
    int expectedMonth = 1;
    int expectedYear = 1;
    while (millis < end) {
        int dowValue = dayOfWeek.get(millis);
        int doyValue = dayOfYear.get(millis);
        int dayValue = dayOfMonth.get(millis);
        int monthValue = monthOfYear.get(millis);
        int yearValue = year.get(millis);
        int yearOfEraValue = yearOfEra.get(millis);
        int monthLen = dayOfMonth.getMaximumValue(millis);
        if (monthValue < 1 || monthValue > 13) {
            fail("Bad month: " + millis);
        }
        
        // test era
        assertEquals(1, era.get(millis));
        assertEquals("EE", era.getAsText(millis));
        assertEquals("EE", era.getAsShortText(millis));
        
        // test date
        assertEquals(expectedYear, yearValue);
        assertEquals(expectedYear, yearOfEraValue);
        assertEquals(expectedMonth, monthValue);
        assertEquals(expectedDay, dayValue);
        assertEquals(expectedDOW, dowValue);
        assertEquals(expectedDOY, doyValue);
        
        // test leap year
        assertEquals(yearValue % 4 == 3, year.isLeap(millis));
        
        // test month length
        if (monthValue == 13) {
            assertEquals(yearValue % 4 == 3, monthOfYear.isLeap(millis));
            if (yearValue % 4 == 3) {
                assertEquals(6, monthLen);
            } else {
                assertEquals(5, monthLen);
            }
        } else {
            assertEquals(30, monthLen);
        }
        
        // recalculate date
        expectedDOW = (((expectedDOW + 1) - 1) % 7) + 1;
        expectedDay++;
        expectedDOY++;
        if (expectedDay == 31 && expectedMonth < 13) {
            expectedDay = 1;
            expectedMonth++;
        } else if (expectedMonth == 13) {
            if (expectedYear % 4 == 3 && expectedDay == 7) {
                expectedDay = 1;
                expectedMonth = 1;
                expectedYear++;
                expectedDOY = 1;
            } else if (expectedYear % 4 != 3 && expectedDay == 6) {
                expectedDay = 1;
                expectedMonth = 1;
                expectedYear++;
                expectedDOY = 1;
            }
        }
        millis += SKIP;
    }
}
 
源代码19 项目: astor   文件: AbstractInstant.java
/**
 * Get the value of one of the fields of a datetime.
 * <p>
 * This could be used to get a field using a different Chronology.
 * For example:
 * <pre>
 * Instant dt = new Instant();
 * int gjYear = dt.get(Chronology.getCoptic().year());
 * </pre>
 * 
 * @param field  the DateTimeField to use, not null
 * @return the value
 * @throws IllegalArgumentException if the field is null
 */
public int get(DateTimeField field) {
    if (field == null) {
        throw new IllegalArgumentException("The DateTimeField must not be null");
    }
    return field.get(getMillis());
}
 
源代码20 项目: astor   文件: AbstractInstant.java
/**
 * Get the value of one of the fields of a datetime.
 * <p>
 * This could be used to get a field using a different Chronology.
 * For example:
 * <pre>
 * Instant dt = new Instant();
 * int gjYear = dt.get(Chronology.getCoptic().year());
 * </pre>
 * 
 * @param field  the DateTimeField to use, not null
 * @return the value
 * @throws IllegalArgumentException if the field is null
 */
public int get(DateTimeField field) {
    if (field == null) {
        throw new IllegalArgumentException("The DateTimeField must not be null");
    }
    return field.get(getMillis());
}