Java Code Examples for java.time.LocalDateTime#getDayOfWeek()
The following examples show how to use
java.time.LocalDateTime#getDayOfWeek() .
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: TestDateUtil.java From sailfish-core with Apache License 2.0 | 6 votes |
@Test public void testBusinessGetDateWithCustomWeekends() { LocalDateTime currentTime = dateUtil.getDateTime(); DayOfWeek dayOfWeek = currentTime.getDayOfWeek(); DayOfWeek customWeekend = DayOfWeek.SUNDAY; int toSunday = customWeekend.getValue() - dayOfWeek.getValue(); String nearestSundayInFuture = "D+" + toSunday; LocalDateTime businessDateTime = dateUtil.getBusinessDateTime(nearestSundayInFuture, customWeekend.name()); assertEquals(DayOfWeek.MONDAY, businessDateTime.getDayOfWeek()); String nearestSundayInPast = "D-" + Math.min(dayOfWeek.getValue(), 6); businessDateTime = dateUtil.getBusinessDateTime(nearestSundayInPast, customWeekend.name()); assertEquals(DayOfWeek.SATURDAY, businessDateTime.getDayOfWeek()); }
Example 2
Source File: HistoricalTesterImpl.java From FX-AlgorithmTrading with MIT License | 6 votes |
/** * 取引を行う時刻かどうか判断します * @param jstDateTime * @return */ public boolean isMarketOpenedTradable(LocalDateTime jstDateTime) { switch (jstDateTime.getDayOfWeek()) { case TUESDAY: case WEDNESDAY: case THURSDAY: case FRIDAY: return true; case MONDAY: return jstDateTime.toLocalTime().isBefore(startTradeMonday) ? false : true; case SATURDAY: if (MarketTimeUtility.isNYCSummer(jstDateTime.toLocalDate())) { return jstDateTime.toLocalTime().isAfter(stopTradeSaturdaySummer) ? false : true; } else { return jstDateTime.toLocalTime().isAfter(stopTradeSaturdayWinter) ? false : true; } case SUNDAY: return false; default: return false; } }
Example 3
Source File: MarketTimeUtility.java From FX-AlgorithmTrading with MIT License | 6 votes |
/** * MarketがOpenしている時間かどうか判断します * * @param jstDateTime * @return */ public static boolean isMarketOpened(LocalDateTime jstDateTime) { switch (jstDateTime.getDayOfWeek()) { case TUESDAY: case WEDNESDAY: case THURSDAY: case FRIDAY: return true; case MONDAY: if (isNYCSummer(jstDateTime.toLocalDate())) { return jstDateTime.toLocalTime().isBefore(OPEN_WEEEK_MONDAY_SUMMER) ? false : true; } else { return jstDateTime.toLocalTime().isBefore(OPEN_WEEEK_MONDAY_WINTER) ? false : true; } case SATURDAY: if (isNYCSummer(jstDateTime.toLocalDate())) { return jstDateTime.toLocalTime().isAfter(CLOSE_WEEEK_SATURDAY_SUMMER) ? false : true; } else { return jstDateTime.toLocalTime().isAfter(CLOSE_WEEEK_SATURDAY_WINTER) ? false : true; } case SUNDAY: return false; default: return false; } }
Example 4
Source File: TestSolution4DateTimePartials.java From java-katas with MIT License | 5 votes |
@Test @Tag("PASSING") @Order(5) public void verifyDayOfWeek() { LocalDateTime tOJDateTime = LocalDateTime.now(terminatorOriginalJudgementDay); // TODO: Replace the null below to get the Day Of Week from the tOJDateTime. // Check: java.time.LocalDateTime.getDayOfWeek() DayOfWeek dayOfWeek = tOJDateTime.getDayOfWeek(); assertEquals(DayOfWeek.FRIDAY, dayOfWeek, "The day of the week enumeration should match Friday."); }
Example 5
Source File: DateUtil.java From sailfish-core with Apache License 2.0 | 5 votes |
private LocalDateTime getBusinessDateTime(LocalDateTime original, LocalDateTime modified, Collection<DayOfWeek> weekends) { LocalDateTime after = DateTimeUtility.toLocalDateTime(modified); LocalDateTime iter = DateTimeUtility.toLocalDateTime(original); boolean past = false; if (after.isBefore(iter)) { past = true; } int counter = past ? -1 : 1; while (past ? !iter.toLocalDate().isBefore(after.toLocalDate()) : !iter.toLocalDate().isAfter(after.toLocalDate())) { DayOfWeek dayOfWeek = iter.getDayOfWeek(); if(weekends.contains(dayOfWeek)) { after = after.plusDays(counter); } iter = iter.plusDays(counter); if (logger.isDebugEnabled()) { logger.debug("{} : {} {}", iter.isAfter(after), iter, after); } } return after; }
Example 6
Source File: MarketTimeUtility.java From FX-AlgorithmTrading with MIT License | 5 votes |
/** * 次の Market Open 時刻を取得します * @param jstDateTime * @return */ public static LocalDateTime getNextOpenTime(LocalDateTime jstDateTime) { // まずSummerで計算する LocalDateTime nextOpenTime = LocalDateTime.of(jstDateTime.getYear(), jstDateTime.getMonth(), jstDateTime.getDayOfMonth(), OPEN_WEEEK_MONDAY_SUMMER.getHour(), OPEN_WEEEK_MONDAY_SUMMER.getMinute()); while (nextOpenTime.getDayOfWeek() != DayOfWeek.MONDAY) { nextOpenTime = nextOpenTime.plusDays(1); } // 日付が確定したら夏冬判定する if (isNYCSummer(nextOpenTime.toLocalDate())) { return nextOpenTime; } else { return nextOpenTime.withHour(OPEN_WEEEK_MONDAY_WINTER.getHour()); } }
Example 7
Source File: Dove.java From JavaMainRepo with Apache License 2.0 | 5 votes |
@Override public double getPredisposition() { LocalDateTime dt = LocalDateTime.now(); if (dt.getDayOfWeek() == DayOfWeek.MONDAY) { // pigeons hate mondays apparently return 1.0; } return 0.0; }
Example 8
Source File: LocalDateTime1.java From java8-tutorial with MIT License | 5 votes |
public static void main(String[] args) { LocalDateTime sylvester = LocalDateTime.of(2014, Month.DECEMBER, 31, 23, 59, 59); DayOfWeek dayOfWeek = sylvester.getDayOfWeek(); System.out.println(dayOfWeek); // WEDNESDAY Month month = sylvester.getMonth(); System.out.println(month); // DECEMBER long minuteOfDay = sylvester.getLong(ChronoField.MINUTE_OF_DAY); System.out.println(minuteOfDay); // 1439 Instant instant = sylvester .atZone(ZoneId.systemDefault()) .toInstant(); Date legacyDate = Date.from(instant); System.out.println(legacyDate); // Wed Dec 31 23:59:59 CET 2014 DateTimeFormatter formatter = DateTimeFormatter .ofPattern("MMM dd, yyyy - HH:mm"); LocalDateTime parsed = LocalDateTime.parse("Nov 03, 2014 - 07:13", formatter); String string = parsed.format(formatter); System.out.println(string); // Nov 03, 2014 - 07:13 }
Example 9
Source File: TimerChecker.java From FX-AlgorithmTrading with MIT License | 4 votes |
/** * TImerの更新をチェックします。 * * @param updateDateTime */ public synchronized void checkTime(LocalDateTime updateDateTime) { LocalDateTime nextDateTime1min = nextDateTimeMap.get(SHORTEST_PERIOD); // 最小更新間隔である1分の更新をチェックして、更新がなければ全部更新しない if (updateDateTime.isBefore(nextDateTime1min)) { return; } // Market Close 時間帯は更新しない if (!MarketTimeUtility.isMarketOpened(nextDateTime1min)) { // 次のOpen時刻まで進める putForwardTimeToNext(MarketTimeUtility.getNextOpenTime(nextDateTime1min)); return; } // 土曜日は Market Close 15分前に WEEK_ENDイベントを送信する if (!onWeekend && updateDateTime.getDayOfWeek() == DayOfWeek.SATURDAY) { LocalTime closeTime = MarketTimeUtility.getCloseWeekTimeSaturday(updateDateTime.toLocalDate()); if(!updateDateTime.toLocalTime().isBefore(closeTime.minusMinutes(WEEKEND_BEFORE_MINUTES))) { onWeekend = true; eventGenarator.sendWeekEndEvent(nextDateTime1min); } } else if (onWeekend && updateDateTime.getDayOfWeek() == DayOfWeek.MONDAY) { // 月曜はStart時刻に開始イベントを送信する LocalTime openTime = MarketTimeUtility.getOpenWeekTimeMonday(updateDateTime.toLocalDate()); if(!updateDateTime.toLocalTime().isBefore(openTime)) { onWeekend = false; eventGenarator.sendWeekStartEvent(nextDateTime1min); } } // 各基準時刻を進める for (Period period : TIMER_PERIODS) { LocalDateTime lastDateTime = lastDateTimeMap.get(period); LocalDateTime nextDateTime = nextDateTimeMap.get(period); // 5min以降の比較用 LocalDateTime lastDateTime1min = lastDateTimeMap.get(SHORTEST_PERIOD); // 現在時刻が次の更新予定時刻以降 if (!updateDateTime.isBefore(nextDateTime)) { // その時刻のMIN_1が更新されていなければ抜ける(先にMIN_1を更新する) if (period != SHORTEST_PERIOD && lastDateTime1min.isBefore(nextDateTime)) { return; } // 更新時刻、次回時刻を設定 lastDateTime = nextDateTime; if (period != Period.DAILY) { nextDateTime = nextDateTime.plus(period.getTimeInverval(), period.getChronoUnit()); } else { nextDateTime = culcurateNextDailyUpdate(nextDateTime.toLocalDate()); } sendTimerEvent(period, lastDateTime, nextDateTime); // LocalDateTime は immutable なので入れなおす lastDateTimeMap.put(period, lastDateTime); nextDateTimeMap.put(period, nextDateTime); } else { // 更新が無い場合、より長い時刻は更新しない return; } } }
Example 10
Source File: GetDayOfWeek.java From levelup-java-examples with Apache License 2.0 | 4 votes |
@Test public void get_day_of_week_java8 () { LocalDate date = LocalDate.of(2014, Month.APRIL, 4); DayOfWeek dayOfWeek = date.getDayOfWeek(); assertEquals(DayOfWeek.FRIDAY, dayOfWeek); // or int dayOfWeek2 = dayOfWeek.get(ChronoField.DAY_OF_WEEK); assertEquals(DayOfWeek.FRIDAY.getValue(), dayOfWeek2); // or LocalDateTime localDateTime = LocalDateTime.of(2014, Month.APRIL, 4, 5, 4); DayOfWeek dayOfWeek3 = localDateTime.getDayOfWeek(); assertEquals(DayOfWeek.FRIDAY, dayOfWeek3); }