Java Code Examples for java.time.zone.ZoneOffsetTransitionRule#getDayOfMonthIndicator()

The following examples show how to use java.time.zone.ZoneOffsetTransitionRule#getDayOfMonthIndicator() . 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: ZoneRules.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Writes the state of the transition rule to the stream.
 *
 * @param rule  the transition rule, not null
 * @param out  the output stream, not null
 * @throws IOException if an error occurs
 */
static void writeRule(ZoneOffsetTransitionRule rule, DataOutput out) throws IOException {
    int month = rule.getMonth().getValue();
    byte dom = (byte)rule.getDayOfMonthIndicator();
    int dow = (rule.getDayOfWeek() == null ? -1 : rule.getDayOfWeek().getValue());
    LocalTime time = rule.getLocalTime();
    boolean timeEndOfDay = rule.isMidnightEndOfDay();
    TimeDefinition timeDefinition = rule.getTimeDefinition();
    ZoneOffset standardOffset = rule.getStandardOffset();
    ZoneOffset offsetBefore = rule.getOffsetBefore();
    ZoneOffset offsetAfter = rule.getOffsetAfter();

    int timeSecs = (timeEndOfDay ? 86400 : time.toSecondOfDay());
    int stdOffset = standardOffset.getTotalSeconds();
    int beforeDiff = offsetBefore.getTotalSeconds() - stdOffset;
    int afterDiff = offsetAfter.getTotalSeconds() - stdOffset;
    int timeByte = (timeSecs % 3600 == 0 ? (timeEndOfDay ? 24 : time.getHour()) : 31);
    int stdOffsetByte = (stdOffset % 900 == 0 ? stdOffset / 900 + 128 : 255);
    int beforeByte = (beforeDiff == 0 || beforeDiff == 1800 || beforeDiff == 3600 ? beforeDiff / 1800 : 3);
    int afterByte = (afterDiff == 0 || afterDiff == 1800 || afterDiff == 3600 ? afterDiff / 1800 : 3);
    int dowByte = (dow == -1 ? 0 : dow);
    int b = (month << 28) +                     // 4 bytes
            ((dom + 32) << 22) +                // 6 bytes
            (dowByte << 19) +                   // 3 bytes
            (timeByte << 14) +                  // 5 bytes
            (timeDefinition.ordinal() << 12) +  // 2 bytes
            (stdOffsetByte << 4) +              // 8 bytes
            (beforeByte << 2) +                 // 2 bytes
            afterByte;                          // 2 bytes
    out.writeInt(b);
    if (timeByte == 31) {
        out.writeInt(timeSecs);
    }
    if (stdOffsetByte == 255) {
        out.writeInt(stdOffset);
    }
    if (beforeByte == 3) {
        out.writeInt(offsetBefore.getTotalSeconds());
    }
    if (afterByte == 3) {
        out.writeInt(offsetAfter.getTotalSeconds());
    }
}
 
Example 2
Source File: TimeZoneRulesImpl.java    From questdb with Apache License 2.0 4 votes vote down vote up
public TimeZoneRulesImpl(ZoneRules rules) {
    final long[] savingsInstantTransition = (long[]) Unsafe.getUnsafe().getObject(rules, SAVING_INSTANT_TRANSITION);

    if (savingsInstantTransition.length == 0) {
        ZoneOffset[] standardOffsets = (ZoneOffset[]) Unsafe.getUnsafe().getObject(rules, STANDARD_OFFSETS);
        standardOffset = standardOffsets[0].getTotalSeconds() * 1000;
    } else {
        standardOffset = Long.MIN_VALUE;
    }

    LocalDateTime[] savingsLocalTransitions = (LocalDateTime[]) Unsafe.getUnsafe().getObject(rules, SAVINGS_LOCAL_TRANSITION);
    for (int i = 0, n = savingsLocalTransitions.length; i < n; i++) {
        LocalDateTime dt = savingsLocalTransitions[i];

        historicTransitions.add(Dates.toMillis(dt.getYear(), dt.getMonthValue(), dt.getDayOfMonth(), dt.getHour(), dt.getMinute()) +
                dt.getSecond() * 1000 + dt.getNano() / 1000000);
    }
    cutoffTransition = historicTransitions.getLast();
    historyOverlapCheckCutoff = historicTransitions.size() - 1;


    ZoneOffsetTransitionRule[] lastRules = (ZoneOffsetTransitionRule[]) Unsafe.getUnsafe().getObject(rules, LAST_RULES);
    this.rules = new ObjList<>(lastRules.length);
    for (int i = 0, n = lastRules.length; i < n; i++) {
        ZoneOffsetTransitionRule zr = lastRules[i];
        TransitionRule tr = new TransitionRule();
        tr.offsetBefore = zr.getOffsetBefore().getTotalSeconds();
        tr.offsetAfter = zr.getOffsetAfter().getTotalSeconds();
        tr.standardOffset = zr.getStandardOffset().getTotalSeconds();
        tr.dow = zr.getDayOfWeek() == null ? -1 : zr.getDayOfWeek().getValue();
        tr.dom = zr.getDayOfMonthIndicator();
        tr.month = zr.getMonth().getValue();
        tr.midnightEOD = zr.isMidnightEndOfDay();
        tr.hour = zr.getLocalTime().getHour();
        tr.minute = zr.getLocalTime().getMinute();
        tr.second = zr.getLocalTime().getSecond();
        switch (zr.getTimeDefinition()) {
            case UTC:
                tr.timeDef = TransitionRule.UTC;
                break;
            case STANDARD:
                tr.timeDef = TransitionRule.STANDARD;
                break;
            default:
                tr.timeDef = TransitionRule.WALL;
                break;
        }
        this.rules.add(tr);
    }

    this.ruleCount = lastRules.length;

    ZoneOffset[] wallOffsets = (ZoneOffset[]) Unsafe.getUnsafe().getObject(rules, WALL_OFFSETS);
    this.wallOffsets = new int[wallOffsets.length];
    for (int i = 0, n = wallOffsets.length; i < n; i++) {
        this.wallOffsets[i] = wallOffsets[i].getTotalSeconds();
    }
    this.firstWall = this.wallOffsets[0] * Dates.SECOND_MILLIS;
    this.lastWall = this.wallOffsets[wallOffsets.length - 1] * Dates.SECOND_MILLIS;
}
 
Example 3
Source File: TimeZoneRulesImpl.java    From questdb with Apache License 2.0 4 votes vote down vote up
public TimeZoneRulesImpl(ZoneRules rules) {
    final long[] savingsInstantTransition = (long[]) Unsafe.getUnsafe().getObject(rules, SAVING_INSTANT_TRANSITION);

    if (savingsInstantTransition.length == 0) {
        ZoneOffset[] standardOffsets = (ZoneOffset[]) Unsafe.getUnsafe().getObject(rules, STANDARD_OFFSETS);
        standardOffset = standardOffsets[0].getTotalSeconds() * Timestamps.SECOND_MICROS;
    } else {
        standardOffset = Long.MIN_VALUE;
    }

    LocalDateTime[] savingsLocalTransitions = (LocalDateTime[]) Unsafe.getUnsafe().getObject(rules, SAVINGS_LOCAL_TRANSITION);
    for (int i = 0, n = savingsLocalTransitions.length; i < n; i++) {
        LocalDateTime dt = savingsLocalTransitions[i];

        historicTransitions.add(Timestamps.toMicros(dt.getYear(), dt.getMonthValue(), dt.getDayOfMonth(), dt.getHour(), dt.getMinute()) +
                dt.getSecond() * Timestamps.SECOND_MICROS + dt.getNano() / 1000);
    }
    cutoffTransition = historicTransitions.getLast();
    historyOverlapCheckCutoff = historicTransitions.size() - 1;


    ZoneOffsetTransitionRule[] lastRules = (ZoneOffsetTransitionRule[]) Unsafe.getUnsafe().getObject(rules, LAST_RULES);
    this.rules = new ObjList<>(lastRules.length);
    for (int i = 0, n = lastRules.length; i < n; i++) {
        ZoneOffsetTransitionRule zr = lastRules[i];
        TransitionRule tr = new TransitionRule();
        tr.offsetBefore = zr.getOffsetBefore().getTotalSeconds();
        tr.offsetAfter = zr.getOffsetAfter().getTotalSeconds();
        tr.standardOffset = zr.getStandardOffset().getTotalSeconds();
        tr.dow = zr.getDayOfWeek() == null ? -1 : zr.getDayOfWeek().getValue();
        tr.dom = zr.getDayOfMonthIndicator();
        tr.month = zr.getMonth().getValue();
        tr.midnightEOD = zr.isMidnightEndOfDay();
        tr.hour = zr.getLocalTime().getHour();
        tr.minute = zr.getLocalTime().getMinute();
        tr.second = zr.getLocalTime().getSecond();
        switch (zr.getTimeDefinition()) {
            case UTC:
                tr.timeDef = TransitionRule.UTC;
                break;
            case STANDARD:
                tr.timeDef = TransitionRule.STANDARD;
                break;
            default:
                tr.timeDef = TransitionRule.WALL;
                break;
        }
        this.rules.add(tr);
    }

    this.ruleCount = lastRules.length;

    ZoneOffset[] wallOffsets = (ZoneOffset[]) Unsafe.getUnsafe().getObject(rules, WALL_OFFSETS);
    this.wallOffsets = new int[wallOffsets.length];
    for (int i = 0, n = wallOffsets.length; i < n; i++) {
        this.wallOffsets[i] = wallOffsets[i].getTotalSeconds();
    }
    this.firstWall = this.wallOffsets[0] * Timestamps.SECOND_MICROS;
    this.lastWall = this.wallOffsets[wallOffsets.length - 1] * Timestamps.SECOND_MICROS;
}