Java Code Examples for java.time.DayOfWeek#of()

The following examples show how to use java.time.DayOfWeek#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZoneOffsetTransitionRule.java    From desugar_jdk_libs with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: ZoneOffsetTransitionRule.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: ZoneOffsetTransitionRule.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example 4
Source File: CronAdjuster.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Check for the nearest working day. E.g. 15W is the nearest working day around the 15th.
 *
 * @param temporal temporal to check
 * @return true if temporal is nearest to working day
 */
static boolean isNearestWorkDay(final Temporal temporal, final int target) {
    final int day = temporal.get(ChronoField.DAY_OF_MONTH);
    final DayOfWeek type = DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK));

    switch (type) {
        case MONDAY:
            return day == target // the actual day
                    || day == target + 1 // target was on a Sunday
                    || (day == target + 2 && day == 3); // target was Saturday 1

        case TUESDAY:
        case WEDNESDAY:
        case THURSDAY:
            return day == target;

        case FRIDAY:
            return day == target || day + 1 == target;

        // not a work day
        default:
        case SATURDAY:
        case SUNDAY:
            return false;
    }
}
 
Example 5
Source File: WeeklyReport.java    From blynk-server with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void addReportSpecificAtTime(StringBuilder sb, ZoneId zoneId) {
    super.addReportSpecificAtTime(sb, zoneId);

    DayOfWeek dayOfWeek = DayOfWeek.of(dayOfTheWeek);
    String dayOfWeekDisplayName = dayOfWeek.getDisplayName(TextStyle.FULL, Locale.US);
    sb.append(" every ").append(dayOfWeekDisplayName);
}
 
Example 6
Source File: DateTimeExamples.java    From Java8InAction with MIT License 5 votes vote down vote up
@Override
public Temporal adjustInto(Temporal temporal) {
    DayOfWeek dow = DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK));
    int dayToAdd = 1;
    if (dow == DayOfWeek.FRIDAY) dayToAdd = 3;
    if (dow == DayOfWeek.SATURDAY) dayToAdd = 2;
    return temporal.plus(dayToAdd, ChronoUnit.DAYS);
}
 
Example 7
Source File: TCKDayOfWeek.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_factory_int_singleton() {
    for (int i = 1; i <= 7; i++) {
        DayOfWeek test = DayOfWeek.of(i);
        assertEquals(test.getValue(), i);
        assertSame(DayOfWeek.of(i), test);
    }
}
 
Example 8
Source File: Adjusters.java    From jphp with Apache License 2.0 5 votes vote down vote up
private static TemporalAdjuster plusBusinessDays(long days) {
    return temporal -> {

        temporal = temporal.plus(getAllDays(temporal.get(DAY_OF_WEEK), days) * Long.signum(days), DAYS);
        DayOfWeek dayOfWeek = DayOfWeek.of(temporal.get(DAY_OF_WEEK));

        if (dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY) {
            temporal = temporal.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
        }

        return temporal;
    };
}
 
Example 9
Source File: TCKDayOfWeek.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_factory_int_singleton() {
    for (int i = 1; i <= 7; i++) {
        DayOfWeek test = DayOfWeek.of(i);
        assertEquals(test.getValue(), i);
        assertSame(DayOfWeek.of(i), test);
    }
}
 
Example 10
Source File: TCKDayOfWeek.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_int_valueTooHigh() {
    DayOfWeek.of(8);
}
 
Example 11
Source File: TCKDayOfWeek.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_int_valueTooHigh() {
    DayOfWeek.of(8);
}
 
Example 12
Source File: PackedLocalDate.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
public static DayOfWeek getDayOfWeek(int packedDate) {
  int dow0 = Math.floorMod((int) toEpochDay(packedDate) + 3, 7);
  return DayOfWeek.of(dow0 + 1);
}
 
Example 13
Source File: TCKDayOfWeek.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_int_valueTooHigh() {
    DayOfWeek.of(8);
}
 
Example 14
Source File: PackedLocalDate.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
public static DayOfWeek getDayOfWeek(int packedDate) {
  int dow0 = Math.floorMod((int) toEpochDay(packedDate) + 3, 7);
  return DayOfWeek.of(dow0 + 1);
}
 
Example 15
Source File: TCKDayOfWeek.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_int_valueTooHigh() {
    DayOfWeek.of(8);
}
 
Example 16
Source File: TCKDayOfWeek.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_int_valueTooLow() {
    DayOfWeek.of(0);
}
 
Example 17
Source File: IntegerColumnDayOfWeekMapper.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public DayOfWeek fromNonNullString(String s) {
    return DayOfWeek.of(Integer.parseInt(s));
}
 
Example 18
Source File: TestIsoChronoImpl.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the ISO Day of Week from a java.util.Calendr DAY_OF_WEEK.
 * @param the java.util.Calendar day of week (1=Sunday, 7=Saturday)
 * @return the ISO DayOfWeek
 */
private DayOfWeek toISOfromCalendarDOW(int i) {
    return DayOfWeek.of(Math.floorMod(i - 2, 7) + 1);
}
 
Example 19
Source File: TestIsoChronoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the ISO Day of Week from a java.util.Calendr DAY_OF_WEEK.
 * @param the java.util.Calendar day of week (1=Sunday, 7=Saturday)
 * @return the ISO DayOfWeek
 */
private DayOfWeek toISOfromCalendarDOW(int i) {
    return DayOfWeek.of(Math.floorMod(i - 2, 7) + 1);
}
 
Example 20
Source File: TestIsoChronoImpl.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the ISO Day of Week from a java.util.Calendr DAY_OF_WEEK.
 * @param the java.util.Calendar day of week (1=Sunday, 7=Saturday)
 * @return the ISO DayOfWeek
 */
private DayOfWeek toISOfromCalendarDOW(int i) {
    return DayOfWeek.of(Math.floorMod(i - 2, 7) + 1);
}