Java Code Examples for java.time.ZonedDateTime#getMonthValue()

The following examples show how to use java.time.ZonedDateTime#getMonthValue() . 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: SingleExecutionTime.java    From cron-utils with Apache License 2.0 6 votes vote down vote up
private Optional<TimeNode> generateDayCandidatesUsingDoY(final ZonedDateTime reference) {
    final int year = reference.getYear();
    final int month = reference.getMonthValue();
    final LocalDate date = LocalDate.of(year, 1, 1);
    final int lengthOfYear = date.lengthOfYear();

    final List<Integer> candidates = createDayOfYearValueGeneratorInstance(daysOfYearCronField, year).generateCandidates(1, lengthOfYear);

    final int low = LocalDate.of(year, month, 1).getDayOfYear();
    final int high = month == 12
            ? LocalDate.of(year, 12, 31).getDayOfYear() + 1
            : LocalDate.of(year, month + 1, 1).getDayOfYear();

    final List<Integer> collectedCandidates = candidates.stream().filter(dayOfYear -> dayOfYear >= low && dayOfYear < high)
            .map(dayOfYear -> LocalDate.ofYearDay(reference.getYear(), dayOfYear).getDayOfMonth())
            .collect(Collectors.toList());

    return Optional.of(collectedCandidates).filter(not(List::isEmpty)).map(TimeNode::new);
}
 
Example 2
Source File: TermExpression.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isMatchDateTime(ZonedDateTime dateTime) {
    int year = dateTime.getYear();
    int month = dateTime.getMonthValue();
    int day = dateTime.getDayOfMonth();
    int term;
    int hour = dateTime.getHour();
    int minute = dateTime.getMinute();
    int second = dateTime.getSecond();
    if (seconds.get(second) && minutes.get(minute) && hours.get(hour)) {
        term = (month - 1) * 2;
        if (TermType.values()[term].getDate(year).getDayOfMonth() == day) {
            return true;
        }
        term++;
        if (TermType.values()[term].getDate(year).getDayOfMonth() == day) {
            return true;
        }
    }
    return false;
}
 
Example 3
Source File: SingleExecutionTime.java    From cron-utils with Apache License 2.0 6 votes vote down vote up
private boolean dateValuesInExpectedRanges(final ZonedDateTime validCronDate, final ZonedDateTime date) {
    boolean everythingInRange = true;
    if (cronDefinition.getFieldDefinition(YEAR) != null) {
        everythingInRange = validCronDate.getYear() == date.getYear();
    }
    if (cronDefinition.getFieldDefinition(MONTH) != null) {
        everythingInRange = everythingInRange && validCronDate.getMonthValue() == date.getMonthValue();
    }
    if (cronDefinition.getFieldDefinition(DAY_OF_MONTH) != null) {
        everythingInRange = everythingInRange && validCronDate.getDayOfMonth() == date.getDayOfMonth();
    }
    if (cronDefinition.getFieldDefinition(DAY_OF_WEEK) != null) {
        everythingInRange = everythingInRange && validCronDate.getDayOfWeek().getValue() == date.getDayOfWeek().getValue();
    }
    if (cronDefinition.getFieldDefinition(HOUR) != null) {
        everythingInRange = everythingInRange && validCronDate.getHour() == date.getHour();
    }
    if (cronDefinition.getFieldDefinition(MINUTE) != null) {
        everythingInRange = everythingInRange && validCronDate.getMinute() == date.getMinute();
    }
    if (cronDefinition.getFieldDefinition(SECOND) != null) {
        everythingInRange = everythingInRange && validCronDate.getSecond() == date.getSecond();
    }
    return everythingInRange;
}
 
Example 4
Source File: JavatimeTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) {
    ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
    return zdt.getYear() == ts.getYear() + 1900 &&
           zdt.getMonthValue() == ts.getMonth() + 1 &&
           zdt.getDayOfMonth() == ts.getDate() &&
           zdt.getHour() == ts.getHours() &&
           zdt.getMinute() == ts.getMinutes() &&
           zdt.getSecond() == ts.getSeconds() &&
           zdt.getNano() == ts.getNanos();
}
 
Example 5
Source File: WallClockTimeImpl.java    From ttt with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Obtain current wall clock time in UTC time zone
 * @return current wall clock time in UTC time zone
 */
public static WallClockTime utc() {
    ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
    int years = now.getYear();
    int months = now.getMonthValue();
    int days = now.getDayOfMonth();
    int hours = now.getHour();
    int minutes = now.getMinute();
    double seconds = (double) now.getSecond() + ((double) now.getNano()) / 1e9;
    return new WallClockTimeImpl(years, months, days, hours, minutes, seconds);
}
 
Example 6
Source File: IncrementalTimeConverterUtil.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static long getStartTimeOfPreviousMonth(long currentEmitTime) {
    ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(currentEmitTime),
            ZoneId.of("GMT"));
    int givenMonth = zonedDateTime.getMonthValue();
    int givenYear = zonedDateTime.getYear();

    if (givenMonth == 1) {
        return ZonedDateTime.of(--givenYear, 12, 1, 0, 0, 0, 0, ZoneId.of("GMT"))
                .toEpochSecond() * 1000;
    } else {
        return ZonedDateTime
                .of(givenYear, --givenMonth, 1, 0, 0, 0, 0, ZoneId.of("GMT"))
                .toEpochSecond() * 1000;
    }
}
 
Example 7
Source File: JavatimeTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) {
    ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
    return zdt.getYear() == ts.getYear() + 1900 &&
           zdt.getMonthValue() == ts.getMonth() + 1 &&
           zdt.getDayOfMonth() == ts.getDate() &&
           zdt.getHour() == ts.getHours() &&
           zdt.getMinute() == ts.getMinutes() &&
           zdt.getSecond() == ts.getSeconds() &&
           zdt.getNano() == ts.getNanos();
}
 
Example 8
Source File: JavatimeTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) {
    ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
    return zdt.getYear() == ts.getYear() + 1900 &&
           zdt.getMonthValue() == ts.getMonth() + 1 &&
           zdt.getDayOfMonth() == ts.getDate() &&
           zdt.getHour() == ts.getHours() &&
           zdt.getMinute() == ts.getMinutes() &&
           zdt.getSecond() == ts.getSeconds() &&
           zdt.getNano() == ts.getNanos();
}
 
Example 9
Source File: TimePartitionGlobFinder.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Refine month options
 */
private static StringBuilder buildMonthOptions(ZonedDateTime start,
    ZonedDateTime end) {
  int startMonth = start.getMonthValue();
  int endMonth = end.getMonthValue();
  int yearDiff = end.getYear() - start.getYear();
  if ( yearDiff > 1 || (yearDiff == 1 && endMonth >= startMonth)) {
    // All 12 months
    return new StringBuilder("*");
  }

  // Append start month
  StringBuilder monthOptions = new StringBuilder("{");
  if (startMonth < 10) {
    monthOptions.append("0");
  }
  monthOptions.append(startMonth);

  if (endMonth >= startMonth) {
    appendOptions(monthOptions, startMonth + 1, endMonth);
  } else {
    // from [startMonth + 1, 12] of start year
    appendOptions(monthOptions, startMonth + 1, 12);
    // from [1, endMonth] of current year
    appendOptions(monthOptions, 1, endMonth);
  }
  monthOptions.append("}");
  return monthOptions;
}
 
Example 10
Source File: JavatimeTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) {
    ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
    return zdt.getYear() == ts.getYear() + 1900 &&
           zdt.getMonthValue() == ts.getMonth() + 1 &&
           zdt.getDayOfMonth() == ts.getDate() &&
           zdt.getHour() == ts.getHours() &&
           zdt.getMinute() == ts.getMinutes() &&
           zdt.getSecond() == ts.getSeconds() &&
           zdt.getNano() == ts.getNanos();
}
 
Example 11
Source File: JavatimeTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) {
    ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
    return zdt.getYear() == ts.getYear() + 1900 &&
           zdt.getMonthValue() == ts.getMonth() + 1 &&
           zdt.getDayOfMonth() == ts.getDate() &&
           zdt.getHour() == ts.getHours() &&
           zdt.getMinute() == ts.getMinutes() &&
           zdt.getSecond() == ts.getSeconds() &&
           zdt.getNano() == ts.getNanos();
}
 
Example 12
Source File: JavatimeTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) {
    ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
    return zdt.getYear() == ts.getYear() + 1900 &&
           zdt.getMonthValue() == ts.getMonth() + 1 &&
           zdt.getDayOfMonth() == ts.getDate() &&
           zdt.getHour() == ts.getHours() &&
           zdt.getMinute() == ts.getMinutes() &&
           zdt.getSecond() == ts.getSeconds() &&
           zdt.getNano() == ts.getNanos();
}
 
Example 13
Source File: JavatimeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) {
    ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
    return zdt.getYear() == ts.getYear() + 1900 &&
           zdt.getMonthValue() == ts.getMonth() + 1 &&
           zdt.getDayOfMonth() == ts.getDate() &&
           zdt.getHour() == ts.getHours() &&
           zdt.getMinute() == ts.getMinutes() &&
           zdt.getSecond() == ts.getSeconds() &&
           zdt.getNano() == ts.getNanos();
}
 
Example 14
Source File: JavatimeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) {
    ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
    return zdt.getYear() == ts.getYear() + 1900 &&
           zdt.getMonthValue() == ts.getMonth() + 1 &&
           zdt.getDayOfMonth() == ts.getDate() &&
           zdt.getHour() == ts.getHours() &&
           zdt.getMinute() == ts.getMinutes() &&
           zdt.getSecond() == ts.getSeconds() &&
           zdt.getNano() == ts.getNanos();
}
 
Example 15
Source File: JavatimeTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) {
    ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
    return zdt.getYear() == ts.getYear() + 1900 &&
           zdt.getMonthValue() == ts.getMonth() + 1 &&
           zdt.getDayOfMonth() == ts.getDate() &&
           zdt.getHour() == ts.getHours() &&
           zdt.getMinute() == ts.getMinutes() &&
           zdt.getSecond() == ts.getSeconds() &&
           zdt.getNano() == ts.getNanos();
}
 
Example 16
Source File: IncrementalTimeConverterUtil.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static long getNextEmitTimeForHour(long currentTime, String timeZone) {
    ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(currentTime),
            ZoneId.of(timeZone));
    if (zonedDateTime.getHour() == 23) {
        if (zonedDateTime.getDayOfMonth() + 1 > zonedDateTime.getMonth().length(zonedDateTime.getYear() % 4 == 0)) {
            // if the current day is the last day of the month
            if (zonedDateTime.getMonthValue() == 12) {
                // For a time in December, emit time should be beginning of January next year
                return ZonedDateTime
                        .of(zonedDateTime.getYear() + 1, 1, 1, 0, 0, 0, 0, ZoneId.of(timeZone))
                        .toEpochSecond() * 1000;
            } else {
                // For any other month, the 1st day of next month must be considered
                return ZonedDateTime.of(zonedDateTime.getYear(), zonedDateTime.getMonthValue() + 1, 1, 0, 0, 0, 0,
                        ZoneId.of(timeZone)).toEpochSecond() * 1000;
            }
        } else {
            // for any other days
            return ZonedDateTime
                    .of(zonedDateTime.getYear(), zonedDateTime.getMonthValue(), zonedDateTime.getDayOfMonth() + 1,
                            0, 0, 0, 0, ZoneId.of(timeZone)).toEpochSecond() * 1000;
        }
    } else  {
        return ZonedDateTime
                .of(zonedDateTime.getYear(), zonedDateTime.getMonthValue(), zonedDateTime.getDayOfMonth(),
                        zonedDateTime.getHour() + 1, 0, 0, 0, ZoneId.of(timeZone)).toEpochSecond() * 1000;
    }
}
 
Example 17
Source File: JavatimeTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) {
    ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
    return zdt.getYear() == ts.getYear() + 1900 &&
           zdt.getMonthValue() == ts.getMonth() + 1 &&
           zdt.getDayOfMonth() == ts.getDate() &&
           zdt.getHour() == ts.getHours() &&
           zdt.getMinute() == ts.getMinutes() &&
           zdt.getSecond() == ts.getSeconds() &&
           zdt.getNano() == ts.getNanos();
}
 
Example 18
Source File: Scatter3dArranger.java    From constellation with Apache License 2.0 4 votes vote down vote up
private float getFloatValueFromObject(Object attributeValue, boolean logarithmic) {
    if (attributeValue == null) {
        return 0.0f;
    }

    if (attributeValue instanceof Float) {
        return scaleValue((float) attributeValue, logarithmic);
    }

    if (attributeValue instanceof Double) {
        return scaleValue((float) attributeValue, logarithmic);
    }

    if (attributeValue instanceof String) {
        String val = (String) attributeValue;
        float finalVal = 0.0f;
        float multiplier = 1;
        for (int i = 0; i < val.length(); i++) {
            char ch = val.charAt(i);
            float chVal = (float) ch;
            finalVal += ((float) chVal) * multiplier;
            multiplier /= 26;
        }
        return scaleValue(finalVal, logarithmic);
    }

    if (attributeValue instanceof Integer) {
        float ret = (Integer) attributeValue;
        return scaleValue(ret, logarithmic);
    }

    if (attributeValue instanceof ConstellationColor) {
        ConstellationColor color = (ConstellationColor) attributeValue;
        float red = color.getRed() / 256;
        float green = color.getGreen() / 256;
        float blue = color.getBlue() / 256;
        return scaleValue((red + green + blue) * 100, logarithmic);
    }

    if (attributeValue instanceof ZonedDateTime) {
        ZonedDateTime c = (ZonedDateTime) attributeValue;
        float year = c.getYear();
        float month = c.getMonthValue();
        float monthDay = c.getDayOfMonth();
        float hour = c.getHour();
        float minute = c.getMinute();
        return scaleValue((year - 2010) + month / 12 + monthDay / (366) + hour / (366 * 24) + minute / (366 * 24 * 60), logarithmic);
    }

    if (attributeValue instanceof RawData) {
        String s = ((RawData) attributeValue).toString();
        return getFloatValueFromObject(s, logarithmic);
    }

    return 0.0f;
}
 
Example 19
Source File: CronExpression.java    From cron with Apache License 2.0 4 votes vote down vote up
@Override
int getValue(ZonedDateTime dateTime) {
    return dateTime.getMonthValue();
}
 
Example 20
Source File: ZonedDateTimeExtractYearMonthDayIntegerValues.java    From tutorials with MIT License 4 votes vote down vote up
int getMonth(ZonedDateTime zonedDateTime) {
    return zonedDateTime.getMonthValue();
}