Search in sources :

Example 6 with Month

use of java.time.Month in project jdk8u_jdk by JetBrains.

the class TCKTemporalAdjusters method test_firstDayOfYear_leap.

@Test
public void test_firstDayOfYear_leap() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(true); i++) {
            LocalDate date = date(2008, month, i);
            LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfYear().adjustInto(date);
            assertEquals(test.getYear(), 2008);
            assertEquals(test.getMonth(), Month.JANUARY);
            assertEquals(test.getDayOfMonth(), 1);
        }
    }
}
Also used : Month(java.time.Month) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 7 with Month

use of java.time.Month in project jdk8u_jdk by JetBrains.

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);
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) DayOfWeek(java.time.DayOfWeek) Month(java.time.Month) Test(org.testng.annotations.Test)

Example 8 with Month

use of java.time.Month in project java8-tutorial by winterbe.

the class LocalDateTime1 method main.

public static void main(String[] args) {
    LocalDateTime sylvester = LocalDateTime.of(2014, Month.DECEMBER, 31, 23, 59, 59);
    DayOfWeek dayOfWeek = sylvester.getDayOfWeek();
    // WEDNESDAY
    System.out.println(dayOfWeek);
    Month month = sylvester.getMonth();
    // DECEMBER
    System.out.println(month);
    long minuteOfDay = sylvester.getLong(ChronoField.MINUTE_OF_DAY);
    // 1439
    System.out.println(minuteOfDay);
    Instant instant = sylvester.atZone(ZoneId.systemDefault()).toInstant();
    Date legacyDate = Date.from(instant);
    // Wed Dec 31 23:59:59 CET 2014
    System.out.println(legacyDate);
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd, yyyy - HH:mm");
    LocalDateTime parsed = LocalDateTime.parse("Nov 03, 2014 - 07:13", formatter);
    String string = parsed.format(formatter);
    // Nov 03, 2014 - 07:13
    System.out.println(string);
}
Also used : LocalDateTime(java.time.LocalDateTime) DayOfWeek(java.time.DayOfWeek) Month(java.time.Month) Instant(java.time.Instant) DateTimeFormatter(java.time.format.DateTimeFormatter) Date(java.util.Date)

Example 9 with Month

use of java.time.Month in project wildfly by wildfly.

the class MonthDayExternalizer method readObject.

@Override
public MonthDay readObject(ObjectInput input) throws IOException, ClassNotFoundException {
    Month month = MonthExternalizer.INSTANCE.readObject(input);
    int day = IndexExternalizer.UNSIGNED_BYTE.readData(input);
    return MonthDay.of(month, day);
}
Also used : Month(java.time.Month)

Example 10 with Month

use of java.time.Month in project jdk8u_jdk by JetBrains.

the class ZoneOffsetTransitionRule method readExternal.

/**
     * Reads the state from the stream.
     *
     * @param in  the input stream, not null
     * @return the created object, not null
     * @throws IOException if an error occurs
     */
static ZoneOffsetTransitionRule readExternal(DataInput in) throws IOException {
    int data = in.readInt();
    Month month = Month.of(data >>> 28);
    int dom = ((data & (63 << 22)) >>> 22) - 32;
    int dowByte = (data & (7 << 19)) >>> 19;
    DayOfWeek dow = dowByte == 0 ? null : DayOfWeek.of(dowByte);
    int timeByte = (data & (31 << 14)) >>> 14;
    TimeDefinition defn = TimeDefinition.values()[(data & (3 << 12)) >>> 12];
    int stdByte = (data & (255 << 4)) >>> 4;
    int beforeByte = (data & (3 << 2)) >>> 2;
    int afterByte = (data & 3);
    LocalTime time = (timeByte == 31 ? LocalTime.ofSecondOfDay(in.readInt()) : LocalTime.of(timeByte % 24, 0));
    ZoneOffset std = (stdByte == 255 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds((stdByte - 128) * 900));
    ZoneOffset before = (beforeByte == 3 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(std.getTotalSeconds() + beforeByte * 1800));
    ZoneOffset after = (afterByte == 3 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(std.getTotalSeconds() + afterByte * 1800));
    return ZoneOffsetTransitionRule.of(month, dom, dow, time, timeByte == 24, defn, std, before, after);
}
Also used : Month(java.time.Month) DayOfWeek(java.time.DayOfWeek) LocalTime(java.time.LocalTime) ZoneOffset(java.time.ZoneOffset)

Aggregations

Month (java.time.Month)24 Test (org.testng.annotations.Test)20 LocalDate (java.time.LocalDate)17 DayOfWeek (java.time.DayOfWeek)8 LocalDateTime (java.time.LocalDateTime)3 DateTimeFormatter (java.time.format.DateTimeFormatter)2 Instant (java.time.Instant)1 LocalTime (java.time.LocalTime)1 YearMonth (java.time.YearMonth)1 ZoneOffset (java.time.ZoneOffset)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1