Java Code Examples for java.time.temporal.ChronoUnit#HOURS
The following examples show how to use
java.time.temporal.ChronoUnit#HOURS .
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: XmlModel.java From ehcache3 with Apache License 2.0 | 6 votes |
public static TemporalUnit convertToJavaTemporalUnit(org.ehcache.xml.model.TimeUnit unit) { switch (unit) { case NANOS: return ChronoUnit.NANOS; case MICROS: return ChronoUnit.MICROS; case MILLIS: return ChronoUnit.MILLIS; case SECONDS: return ChronoUnit.SECONDS; case MINUTES: return ChronoUnit.MINUTES; case HOURS: return ChronoUnit.HOURS; case DAYS: return ChronoUnit.DAYS; default: throw new IllegalArgumentException("Unknown time unit: " + unit); } }
Example 2
Source File: ExpiryUtils.java From ehcache3 with Apache License 2.0 | 6 votes |
public static TemporalUnit jucTimeUnitToTemporalUnit(TimeUnit timeUnit) { switch (timeUnit) { case NANOSECONDS: return ChronoUnit.NANOS; case MICROSECONDS: return ChronoUnit.MICROS; case MILLISECONDS: return ChronoUnit.MILLIS; case SECONDS: return ChronoUnit.SECONDS; case MINUTES: return ChronoUnit.MINUTES; case HOURS: return ChronoUnit.HOURS; case DAYS: return ChronoUnit.DAYS; default: throw new AssertionError("Unkown TimeUnit: " + timeUnit); } }
Example 3
Source File: Cache.java From chart-fx with Apache License 2.0 | 6 votes |
protected static ChronoUnit convertToChronoUnit(final TimeUnit timeUnit) { switch (timeUnit) { case NANOSECONDS: return ChronoUnit.NANOS; case MICROSECONDS: return ChronoUnit.MICROS; case SECONDS: return ChronoUnit.SECONDS; case MINUTES: return ChronoUnit.MINUTES; case HOURS: return ChronoUnit.HOURS; case DAYS: return ChronoUnit.DAYS; case MILLISECONDS: default: return ChronoUnit.MILLIS; } }
Example 4
Source File: DateMatchers.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
private static ChronoUnit convertUnit(final TimeUnit unit) { switch (unit) { case DAYS: return ChronoUnit.DAYS; case HOURS: return ChronoUnit.HOURS; case MICROSECONDS: return ChronoUnit.MICROS; case MILLISECONDS: return ChronoUnit.MILLIS; case MINUTES: return ChronoUnit.MINUTES; case NANOSECONDS: return ChronoUnit.NANOS; case SECONDS: return ChronoUnit.SECONDS; default: throw new IllegalArgumentException("Unknown TimeUnit '" + unit + "'"); } }
Example 5
Source File: DurationParser.java From spring-vault with Apache License 2.0 | 6 votes |
/** * Format a {@link Duration} into the Go format representation. * @param duration the duration object to format. * @return the duration formatted in Go's duration format. */ public static String formatDuration(Duration duration) { StringBuilder builder = new StringBuilder(); for (TemporalUnit unit : duration.getUnits()) { if (unit == ChronoUnit.MINUTES) { builder.append(duration.get(unit)).append('m'); } if (unit == ChronoUnit.HOURS) { builder.append(duration.get(unit)).append('h'); } if (unit == ChronoUnit.SECONDS) { builder.append(duration.get(unit)).append('s'); } if (unit == ChronoUnit.MILLIS) { builder.append(duration.get(unit)).append("ms"); } if (unit == ChronoUnit.NANOS) { builder.append(duration.get(unit)).append("ns"); } } return builder.toString(); }
Example 6
Source File: FuzzyValues.java From icure-backend with GNU General Public License v2.0 | 6 votes |
public static long getFuzzyDateTime(LocalDateTime dateTime, TemporalUnit precision) { int seconds = dateTime.getSecond(); /*if (seconds == 0 && precision==ChronoUnit.SECONDS) { seconds = 60; dateTime = dateTime.minusMinutes(1); }*/ int minutes = dateTime.getMinute(); if (minutes == 0 && precision == ChronoUnit.MINUTES) { minutes = 60; dateTime = dateTime.minusHours(1); } int hours = dateTime.getHour(); if (hours == 0 && precision == ChronoUnit.HOURS) { hours = 24; dateTime = dateTime.minusDays(1); } return getFuzzyDate(dateTime, precision) * 1000000l + (precision == ChronoUnit.DAYS ? 0 : ( hours * 10000l + (precision == ChronoUnit.HOURS ? 0 : ( minutes * 100l + (precision == ChronoUnit.MINUTES ? 0 : seconds))))); }
Example 7
Source File: ManualExecutor.java From java-coroutines with BSD 2-Clause "Simplified" License | 6 votes |
private ChronoUnit toChronoUnit(final TimeUnit unit) { switch (unit) { case NANOSECONDS: case MICROSECONDS: return ChronoUnit.MICROS; case MILLISECONDS: return ChronoUnit.MILLIS; case SECONDS: return ChronoUnit.SECONDS; case MINUTES: return ChronoUnit.MINUTES; case HOURS: return ChronoUnit.HOURS; case DAYS: return ChronoUnit.DAYS; default: throw new AssertionError(); } }
Example 8
Source File: ChronoUnits.java From kieker with Apache License 2.0 | 6 votes |
/** * Will be obsolete in Java 9 and can be replaced by {@code TimeUnit.toChronoUnit()}. * See: https://bugs.openjdk.java.net/browse/JDK-8141452 * */ public static ChronoUnit createFromTimeUnit(final TimeUnit timeUnit) { switch (timeUnit) { case DAYS: return ChronoUnit.DAYS; case HOURS: return ChronoUnit.HOURS; case MINUTES: return ChronoUnit.MINUTES; case SECONDS: return ChronoUnit.SECONDS; case MILLISECONDS: return ChronoUnit.MILLIS; case MICROSECONDS: return ChronoUnit.MICROS; case NANOSECONDS: return ChronoUnit.NANOS; default: throw new IllegalArgumentException("Unknown TimeUnit constant"); } }
Example 9
Source File: Timeouts.java From tascalate-concurrent with Apache License 2.0 | 6 votes |
private static ChronoUnit toChronoUnit(TimeUnit unit) { Objects.requireNonNull(unit, "unit"); switch (unit) { case NANOSECONDS: return ChronoUnit.NANOS; case MICROSECONDS: return ChronoUnit.MICROS; case MILLISECONDS: return ChronoUnit.MILLIS; case SECONDS: return ChronoUnit.SECONDS; case MINUTES: return ChronoUnit.MINUTES; case HOURS: return ChronoUnit.HOURS; case DAYS: return ChronoUnit.DAYS; default: throw new IllegalArgumentException("Unknown TimeUnit constant"); } }
Example 10
Source File: FHIRPathUtil.java From FHIR with Apache License 2.0 | 6 votes |
public static ChronoUnit getChronoUnit(String unit) { switch (unit) { case "years": return ChronoUnit.YEARS; case "months": return ChronoUnit.MONTHS; case "weeks": return ChronoUnit.WEEKS; case "days": return ChronoUnit.DAYS; case "hours": return ChronoUnit.HOURS; case "minutes": return ChronoUnit.MINUTES; case "seconds": return ChronoUnit.SECONDS; case "milliseconds": return ChronoUnit.MILLIS; default: throw new IllegalArgumentException("Unsupported unit: " + unit); } }
Example 11
Source File: TimeUtils.java From flink with Apache License 2.0 | 5 votes |
private static ChronoUnit toChronoUnit(java.util.concurrent.TimeUnit timeUnit) { switch(timeUnit) { case NANOSECONDS: return ChronoUnit.NANOS; case MICROSECONDS: return ChronoUnit.MICROS; case MILLISECONDS: return ChronoUnit.MILLIS; case SECONDS: return ChronoUnit.SECONDS; case MINUTES: return ChronoUnit.MINUTES; case HOURS: return ChronoUnit.HOURS; case DAYS: return ChronoUnit.DAYS; default: throw new IllegalArgumentException(String.format("Unsupported time unit %s.", timeUnit)); } }
Example 12
Source File: FindResult.java From find with MIT License | 5 votes |
@SuppressWarnings("TypeMayBeWeakened") private ZonedDateTime parseRelativeTime(final ZonedDateTime timeNow, final int timeAmount, final String timeUnit) { TemporalUnit temporalUnit = ChronoUnit.SECONDS; switch (timeUnit) { case "minute": case "minutes": temporalUnit = ChronoUnit.MINUTES; break; case "hour": case "hours": temporalUnit = ChronoUnit.HOURS; break; case "day": case "days": temporalUnit = ChronoUnit.DAYS; break; case "month": case "months": temporalUnit = ChronoUnit.MONTHS; break; case "year": case "years": temporalUnit = ChronoUnit.YEARS; break; } return timeNow.plus(timeAmount, temporalUnit); }
Example 13
Source File: PeriodFormats.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
private static long periodAmount(TemporalUnit unit, Duration duration) { if (unit == ChronoUnit.DAYS) { return duration.toDays(); } else if (unit == ChronoUnit.HOURS) { return duration.toHours(); } else if (unit == ChronoUnit.MINUTES) { return duration.toMinutes(); } else if (unit == ChronoUnit.SECONDS) { return duration.getSeconds(); } else if (unit == ChronoUnit.MILLIS) { return duration.toMillis(); } else { throw new IllegalArgumentException("Unsupported time unit: " + unit); } }
Example 14
Source File: ClusteringServiceConfigurationBuilder.java From ehcache3 with Apache License 2.0 | 5 votes |
private static ChronoUnit toChronoUnit(TimeUnit unit) { if(unit == null) { return null; } switch (unit) { case NANOSECONDS: return ChronoUnit.NANOS; case MICROSECONDS: return ChronoUnit.MICROS; case MILLISECONDS: return ChronoUnit.MILLIS; case SECONDS: return ChronoUnit.SECONDS; case MINUTES: return ChronoUnit.MINUTES; case HOURS: return ChronoUnit.HOURS; case DAYS: return ChronoUnit.DAYS; default: throw new AssertionError("Unknown unit: " + unit); } }
Example 15
Source File: OkHttpFakeDeadline.java From symbol-sdk-java with Apache License 2.0 | 4 votes |
public OkHttpFakeDeadline() { super(1, ChronoUnit.HOURS); }
Example 16
Source File: ChronoConverterUtilsImpl.java From IridiumApplicationTesting with MIT License | 4 votes |
@Override public ChronoUnit fromString(@NotNull final String input) { checkArgument(StringUtils.isNotBlank(input)); if ("Nanos".equalsIgnoreCase(input) || "Nano".equalsIgnoreCase(input)) { return ChronoUnit.NANOS; } if ("Micros".equalsIgnoreCase(input) || "Micro".equalsIgnoreCase(input)) { return ChronoUnit.MICROS; } if ("Millis".equalsIgnoreCase(input) || "Milli".equalsIgnoreCase(input)) { return ChronoUnit.MILLIS; } if ("Seconds".equalsIgnoreCase(input) || "Second".equalsIgnoreCase(input)) { return ChronoUnit.SECONDS; } if ("Minutes".equalsIgnoreCase(input) || "Minute".equalsIgnoreCase(input)) { return ChronoUnit.MINUTES; } if ("Hours".equalsIgnoreCase(input) || "Hour".equalsIgnoreCase(input)) { return ChronoUnit.HOURS; } if ("HalfDays".equalsIgnoreCase(input) || "HalfDay".equalsIgnoreCase(input)) { return ChronoUnit.HALF_DAYS; } if ("Days".equalsIgnoreCase(input) || "Day".equalsIgnoreCase(input)) { return ChronoUnit.DAYS; } if ("Weeks".equalsIgnoreCase(input) || "Week".equalsIgnoreCase(input)) { return ChronoUnit.WEEKS; } if ("Months".equalsIgnoreCase(input) || "Month".equalsIgnoreCase(input)) { return ChronoUnit.MONTHS; } if ("Years".equalsIgnoreCase(input) || "Year".equalsIgnoreCase(input)) { return ChronoUnit.YEARS; } if ("Decades".equalsIgnoreCase(input) || "Decade".equalsIgnoreCase(input)) { return ChronoUnit.DECADES; } if ("Centuries".equalsIgnoreCase(input) || "Century".equalsIgnoreCase(input)) { return ChronoUnit.CENTURIES; } if ("Millennia".equalsIgnoreCase(input)) { return ChronoUnit.MILLENNIA; } if ("Eras".equalsIgnoreCase(input) || "Era".equalsIgnoreCase(input)) { return ChronoUnit.ERAS; } if ("Forever".equalsIgnoreCase(input)) { return ChronoUnit.FOREVER; } throw new InvalidInputException(input + " is not a valid ChronoUnit"); }
Example 17
Source File: VertxFakeDeadline.java From symbol-sdk-java with Apache License 2.0 | 4 votes |
public VertxFakeDeadline() { super(1, ChronoUnit.HOURS); }
Example 18
Source File: TimeUtil.java From L2jOrg with GNU General Public License v3.0 | 4 votes |
/** * Parses patterns like: * <ul> * <li>1min or 10mins</li> * <li>1day or 10days</li> * <li>1week or 4weeks</li> * <li>1month or 12months</li> * <li>1year or 5years</li> * </ul> * @param datePattern * @return {@link Duration} object converted by the date pattern specified. * @throws IllegalStateException when malformed pattern specified. */ public static Duration parseDuration(String datePattern) { final int index = findIndexOfNonDigit(datePattern); if (index == -1) { throw new IllegalStateException("Incorrect time format given: " + datePattern); } try { final int val = Integer.parseInt(datePattern.substring(0, index)); final String type = datePattern.substring(index); final ChronoUnit unit; switch (type.toLowerCase()) { case "sec": case "secs": { unit = ChronoUnit.SECONDS; break; } case "min": case "mins": { unit = ChronoUnit.MINUTES; break; } case "hour": case "hours": { unit = ChronoUnit.HOURS; break; } case "day": case "days": { unit = ChronoUnit.DAYS; break; } case "week": case "weeks": { unit = ChronoUnit.WEEKS; break; } case "month": case "months": { unit = ChronoUnit.MONTHS; break; } case "year": case "years": { unit = ChronoUnit.YEARS; break; } default: { unit = ChronoUnit.valueOf(type); if (unit == null) { throw new IllegalStateException("Incorrect format: " + type + " !!"); } } } return Duration.of(val, unit); } catch (Exception e) { throw new IllegalStateException("Incorrect time format given: " + datePattern + " val: " + datePattern.substring(0, index)); } }
Example 19
Source File: DurationRandomizer.java From easy-random with MIT License | 2 votes |
/** * Create a new {@link DurationRandomizer}. * Generated {@link Duration} objects will use {@link ChronoUnit#HOURS}. */ public DurationRandomizer() { this(ChronoUnit.HOURS); }
Example 20
Source File: Deadline.java From symbol-sdk-java with Apache License 2.0 | 2 votes |
/** * Create the default deadline of 2 hours. * * @return {@link Deadline} */ public static Deadline create() { return new Deadline(2, ChronoUnit.HOURS); }