Java Code Examples for java.time.LocalTime#ofSecondOfDay()
The following examples show how to use
java.time.LocalTime#ofSecondOfDay() .
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 Bytecoder with Apache License 2.0 | 6 votes |
/** * 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 hottub with GNU General Public License v2.0 | 6 votes |
/** * 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 openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * 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: ZoneOffsetTransitionRule.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * 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 5
Source File: RaidsTimer.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
@Override public String getText() { if (startTime == null) { return ""; } if (!stopped) { Duration elapsed = Duration.between(startTime, Instant.now()); time = LocalTime.ofSecondOfDay(elapsed.getSeconds()); } if (time.getHour() > 0) { return time.format(DateTimeFormatter.ofPattern("HH:mm")); } return time.format(DateTimeFormatter.ofPattern("mm:ss")); }
Example 6
Source File: TestLocalTime.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Test public void factory_ofSecondOfDay_singletons() { for (int i = 0; i < 24; i++) { LocalTime test1 = LocalTime.ofSecondOfDay(i * 60L * 60L); LocalTime test2 = LocalTime.of(i, 0); assertSame(test1, test2); } }
Example 7
Source File: DvTime.java From archie with Apache License 2.0 | 5 votes |
public void setMagnitude(Double magnitude) { if(magnitude == null) { value = null; } else { value = LocalTime.ofSecondOfDay(Math.round(magnitude)); } }
Example 8
Source File: LocalTimeExample.java From journaldev with MIT License | 5 votes |
public static void main(String[] args) { //Current Time LocalTime time = LocalTime.now(); System.out.println("Current Time="+time); //Creating LocalTime by providing input arguments LocalTime specificTime = LocalTime.of(12,20,25,40); System.out.println("Specific Time of Day="+specificTime); //Try creating time by providing invalid inputs //LocalTime invalidTime = LocalTime.of(25,20); //Exception in thread "main" java.time.DateTimeException: //Invalid value for HourOfDay (valid values 0 - 23): 25 //Current date in "Asia/Kolkata", you can get it from ZoneId javadoc LocalTime timeKolkata = LocalTime.now(ZoneId.of("Asia/Kolkata")); System.out.println("Current Time in IST="+timeKolkata); //java.time.zone.ZoneRulesException: Unknown time-zone ID: IST //LocalTime todayIST = LocalTime.now(ZoneId.of("IST")); //Getting date from the base date i.e 01/01/1970 LocalTime specificSecondTime = LocalTime.ofSecondOfDay(10000); System.out.println("10000th second time= "+specificSecondTime); }
Example 9
Source File: ReportButtonPlugin.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
private String getLoginTime() { if (loginTime == null) { return "Report"; } Duration duration = Duration.between(loginTime, Instant.now()); LocalTime time = LocalTime.ofSecondOfDay(duration.getSeconds()); return time.format(DateTimeFormatter.ofPattern("HH:mm:ss")); }
Example 10
Source File: LocalTimeRangeRandomizerTest.java From easy-random with MIT License | 5 votes |
@Test void generatedLocalTimeShouldBeAlwaysTheSameForTheSameSeed() { // Given randomizer = aNewLocalTimeRangeRandomizer(minTime, maxTime, SEED); LocalTime expected = LocalTime.ofSecondOfDay(62481); // When LocalTime randomValue = randomizer.getRandomValue(); // Then assertThat(randomValue).isEqualTo(expected); }
Example 11
Source File: TCKLocalTime.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Test public void factory_ofSecondOfDay() { LocalTime localTime = LocalTime.ofSecondOfDay(2 * 60 * 60 + 17 * 60 + 23); check(localTime, 2, 17, 23, 0); }
Example 12
Source File: TCKLocalTime.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void factory_ofSecondOfDay_tooHigh() { LocalTime.ofSecondOfDay(24 * 60 * 60); }
Example 13
Source File: TCKLocalTime.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
@Test public void factory_ofSecondOfDay() { LocalTime localTime = LocalTime.ofSecondOfDay(2 * 60 * 60 + 17 * 60 + 23); check(localTime, 2, 17, 23, 0); }
Example 14
Source File: TCKLocalTime.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void factory_ofSecondOfDay_tooLow() { LocalTime.ofSecondOfDay(-1); }
Example 15
Source File: TCKLocalTime.java From hottub with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void factory_ofSecondOfDay_tooHigh() { LocalTime.ofSecondOfDay(24 * 60 * 60); }
Example 16
Source File: TCKLocalTime.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Test public void factory_ofSecondOfDay() { LocalTime localTime = LocalTime.ofSecondOfDay(2 * 60 * 60 + 17 * 60 + 23); check(localTime, 2, 17, 23, 0); }
Example 17
Source File: TCKLocalTime.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void factory_ofSecondOfDay_tooLow() { LocalTime.ofSecondOfDay(-1); }
Example 18
Source File: IcuZoneRulesProvider.java From j2objc with Apache License 2.0 | 4 votes |
/** * Transform an {@link AnnualTimeZoneRule} into an equivalent {@link ZoneOffsetTransitionRule}. * This is only used for the "final rules". * * @param rule * The rule to transform. * @param dstSavingMillisBefore * The DST offset before the first transition in milliseconds. */ private static ZoneOffsetTransitionRule toZoneOffsetTransitionRule( AnnualTimeZoneRule rule, int dstSavingMillisBefore) { DateTimeRule dateTimeRule = rule.getRule(); // Calendar.JANUARY is 0, transform it into a proper Month. Month month = Month.JANUARY.plus(dateTimeRule.getRuleMonth()); int dayOfMonthIndicator; // Calendar.SUNDAY is 1, transform it into a proper DayOfWeek. DayOfWeek dayOfWeek = DayOfWeek.SATURDAY.plus(dateTimeRule.getRuleDayOfWeek()); switch (dateTimeRule.getDateRuleType()) { case DateTimeRule.DOM: // Transition always on a specific day of the month. dayOfMonthIndicator = dateTimeRule.getRuleDayOfMonth(); dayOfWeek = null; break; case DateTimeRule.DOW_GEQ_DOM: // ICU representation matches java.time representation. dayOfMonthIndicator = dateTimeRule.getRuleDayOfMonth(); break; case DateTimeRule.DOW_LEQ_DOM: // java.time uses a negative dayOfMonthIndicator to represent "Sun<=X" or "lastSun" // rules. ICU uses this constant and the normal day. So "lastSun" in January would // ruleDayOfMonth = 31 in ICU and dayOfMonthIndicator = -1 in java.time. dayOfMonthIndicator = -month.maxLength() + dateTimeRule.getRuleDayOfMonth() - 1; break; case DateTimeRule.DOW: // DOW is unspecified in the documentation and seems to never be used. throw new ZoneRulesException("Date rule type DOW is unsupported"); default: throw new ZoneRulesException( "Unexpected date rule type: " + dateTimeRule.getDateRuleType()); } // Cast to int is save, as input is int. int secondOfDay = (int) TimeUnit.MILLISECONDS.toSeconds(dateTimeRule.getRuleMillisInDay()); LocalTime time; boolean timeEndOfDay; if (secondOfDay == SECONDS_IN_DAY) { time = LocalTime.MIDNIGHT; timeEndOfDay = true; } else { time = LocalTime.ofSecondOfDay(secondOfDay); timeEndOfDay = false; } ZoneOffsetTransitionRule.TimeDefinition timeDefinition; switch (dateTimeRule.getTimeRuleType()) { case DateTimeRule.WALL_TIME: timeDefinition = ZoneOffsetTransitionRule.TimeDefinition.WALL; break; case DateTimeRule.STANDARD_TIME: timeDefinition = ZoneOffsetTransitionRule.TimeDefinition.STANDARD; break; case DateTimeRule.UTC_TIME: timeDefinition = ZoneOffsetTransitionRule.TimeDefinition.UTC; break; default: throw new ZoneRulesException( "Unexpected time rule type " + dateTimeRule.getTimeRuleType()); } ZoneOffset standardOffset = millisToOffset(rule.getRawOffset()); ZoneOffset offsetBefore = millisToOffset(rule.getRawOffset() + dstSavingMillisBefore); ZoneOffset offsetAfter = millisToOffset( rule.getRawOffset() + rule.getDSTSavings()); return ZoneOffsetTransitionRule.of( month, dayOfMonthIndicator, dayOfWeek, time, timeEndOfDay, timeDefinition, standardOffset, offsetBefore, offsetAfter); }
Example 19
Source File: TCKLocalTime.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test public void factory_ofSecondOfDay() { LocalTime localTime = LocalTime.ofSecondOfDay(2 * 60 * 60 + 17 * 60 + 23); check(localTime, 2, 17, 23, 0); }
Example 20
Source File: TCKLocalTime.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void factory_ofSecondOfDay_tooLow() { LocalTime.ofSecondOfDay(-1); }