use of java.time.Month in project j2objc by google.
the class TCKTemporalAdjusters method test_next.
@Test
public void test_next() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
for (DayOfWeek dow : DayOfWeek.values()) {
LocalDate test = (LocalDate) TemporalAdjusters.next(dow).adjustInto(date);
assertSame(date + " " + test, test.getDayOfWeek(), dow);
if (test.getYear() == 2007) {
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
assertTrue(dayDiff > 0 && dayDiff < 8);
} else {
assertSame(month, Month.DECEMBER);
assertTrue(date.getDayOfMonth() > 24);
assertEquals(test.getYear(), 2008);
assertSame(test.getMonth(), Month.JANUARY);
assertTrue(test.getDayOfMonth() < 8);
}
}
}
}
}
use of java.time.Month in project j2objc by google.
the class TCKLocalDateTime method test_getDayOfWeek.
// -----------------------------------------------------------------------
// getDayOfWeek()
// -----------------------------------------------------------------------
@Test
public void test_getDayOfWeek() {
DayOfWeek dow = DayOfWeek.MONDAY;
for (Month month : Month.values()) {
int length = month.length(false);
for (int i = 1; i <= length; i++) {
LocalDateTime d = LocalDateTime.of(LocalDate.of(2007, month, i), TEST_2007_07_15_12_30_40_987654321.toLocalTime());
assertSame(d.getDayOfWeek(), dow);
dow = dow.plus(1);
}
}
}
use of java.time.Month in project j2objc by google.
the class TCKDateTimeTextPrinting method test_appendTextMap.
// -----------------------------------------------------------------------
@Test
public void test_appendTextMap() throws Exception {
Map<Long, String> map = new HashMap<Long, String>();
map.put(1L, "JNY");
map.put(2L, "FBY");
map.put(3L, "MCH");
map.put(4L, "APL");
map.put(5L, "MAY");
map.put(6L, "JUN");
map.put(7L, "JLY");
map.put(8L, "AGT");
map.put(9L, "SPT");
map.put(10L, "OBR");
map.put(11L, "NVR");
map.put(12L, "DBR");
builder.appendText(MONTH_OF_YEAR, map);
DateTimeFormatter f = builder.toFormatter();
LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0);
for (Month month : Month.values()) {
assertEquals(f.format(dt.with(month)), map.get((long) month.getValue()));
}
}
use of java.time.Month in project j2objc by google.
the class IcuZoneRulesProvider method toZoneOffsetTransitionRule.
/**
* Transform an {@link AnnualTimeZoneRule} into an equivalent {@link ZoneOffsetTransitionRule}.
* This is only used for the "final rules".
*
* @param rule
* The rule to transform.
* @param dstSavingMillisBefore
* The DST offset before the first transition in milliseconds.
*/
private static ZoneOffsetTransitionRule toZoneOffsetTransitionRule(AnnualTimeZoneRule rule, int dstSavingMillisBefore) {
DateTimeRule dateTimeRule = rule.getRule();
// Calendar.JANUARY is 0, transform it into a proper Month.
Month month = Month.JANUARY.plus(dateTimeRule.getRuleMonth());
int dayOfMonthIndicator;
// Calendar.SUNDAY is 1, transform it into a proper DayOfWeek.
DayOfWeek dayOfWeek = DayOfWeek.SATURDAY.plus(dateTimeRule.getRuleDayOfWeek());
switch(dateTimeRule.getDateRuleType()) {
case DateTimeRule.DOM:
// Transition always on a specific day of the month.
dayOfMonthIndicator = dateTimeRule.getRuleDayOfMonth();
dayOfWeek = null;
break;
case DateTimeRule.DOW_GEQ_DOM:
// ICU representation matches java.time representation.
dayOfMonthIndicator = dateTimeRule.getRuleDayOfMonth();
break;
case DateTimeRule.DOW_LEQ_DOM:
// java.time uses a negative dayOfMonthIndicator to represent "Sun<=X" or "lastSun"
// rules. ICU uses this constant and the normal day. So "lastSun" in January would
// ruleDayOfMonth = 31 in ICU and dayOfMonthIndicator = -1 in java.time.
dayOfMonthIndicator = -month.maxLength() + dateTimeRule.getRuleDayOfMonth() - 1;
break;
case DateTimeRule.DOW:
// DOW is unspecified in the documentation and seems to never be used.
throw new ZoneRulesException("Date rule type DOW is unsupported");
default:
throw new ZoneRulesException("Unexpected date rule type: " + dateTimeRule.getDateRuleType());
}
// Cast to int is save, as input is int.
int secondOfDay = (int) TimeUnit.MILLISECONDS.toSeconds(dateTimeRule.getRuleMillisInDay());
LocalTime time;
boolean timeEndOfDay;
if (secondOfDay == SECONDS_IN_DAY) {
time = LocalTime.MIDNIGHT;
timeEndOfDay = true;
} else {
time = LocalTime.ofSecondOfDay(secondOfDay);
timeEndOfDay = false;
}
ZoneOffsetTransitionRule.TimeDefinition timeDefinition;
switch(dateTimeRule.getTimeRuleType()) {
case DateTimeRule.WALL_TIME:
timeDefinition = ZoneOffsetTransitionRule.TimeDefinition.WALL;
break;
case DateTimeRule.STANDARD_TIME:
timeDefinition = ZoneOffsetTransitionRule.TimeDefinition.STANDARD;
break;
case DateTimeRule.UTC_TIME:
timeDefinition = ZoneOffsetTransitionRule.TimeDefinition.UTC;
break;
default:
throw new ZoneRulesException("Unexpected time rule type " + dateTimeRule.getTimeRuleType());
}
ZoneOffset standardOffset = millisToOffset(rule.getRawOffset());
ZoneOffset offsetBefore = millisToOffset(rule.getRawOffset() + dstSavingMillisBefore);
ZoneOffset offsetAfter = millisToOffset(rule.getRawOffset() + rule.getDSTSavings());
return ZoneOffsetTransitionRule.of(month, dayOfMonthIndicator, dayOfWeek, time, timeEndOfDay, timeDefinition, standardOffset, offsetBefore, offsetAfter);
}
use of java.time.Month in project j2objc by google.
the class TCKMonth method test_factory_int_singleton.
// -----------------------------------------------------------------------
@Test
public void test_factory_int_singleton() {
for (int i = 1; i <= MAX_LENGTH; i++) {
Month test = Month.of(i);
assertEquals(test.getValue(), i);
}
}
Aggregations