Java Code Examples for java.time.LocalDateTime#withHour()

The following examples show how to use java.time.LocalDateTime#withHour() . 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: TCKLocalDateTime.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_withHour_normal() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
    for (int i = 0; i < 24; i++) {
        t = t.withHour(i);
        assertEquals(t.getHour(), i);
    }
}
 
Example 2
Source File: TCKLocalDateTime.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void test_withHour_normal() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
    for (int i = 0; i < 24; i++) {
        t = t.withHour(i);
        assertEquals(t.getHour(), i);
    }
}
 
Example 3
Source File: ImportDateTime.java    From axelor-open-suite with GNU Affero General Public License v3.0 5 votes vote down vote up
public LocalDateTime updateHour(LocalDateTime datetime, String hour) {
  if (!Strings.isNullOrEmpty(hour)) {
    Matcher matcher = patternMonth.matcher(hour);
    if (matcher.find()) {
      Long hours = Long.parseLong(matcher.group());
      if (hour.startsWith("+")) datetime = datetime.plusHours(hours);
      else if (hour.startsWith("-")) datetime = datetime.minusHours(hours);
      else datetime = datetime.withHour(hours.intValue());
    }
  }
  return datetime;
}
 
Example 4
Source File: TCKLocalDateTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_withHour_normal() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
    for (int i = 0; i < 24; i++) {
        t = t.withHour(i);
        assertEquals(t.getHour(), i);
    }
}
 
Example 5
Source File: TCKLocalDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_withHour_normal() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
    for (int i = 0; i < 24; i++) {
        t = t.withHour(i);
        assertEquals(t.getHour(), i);
    }
}
 
Example 6
Source File: MarketTimeUtility.java    From FX-AlgorithmTrading with MIT License 5 votes vote down vote up
/**
 * 次の 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: TCKLocalDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_withHour_normal() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
    for (int i = 0; i < 24; i++) {
        t = t.withHour(i);
        assertEquals(t.getHour(), i);
    }
}
 
Example 8
Source File: TCKLocalDateTime.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_withHour_normal() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
    for (int i = 0; i < 24; i++) {
        t = t.withHour(i);
        assertEquals(t.getHour(), i);
    }
}
 
Example 9
Source File: TCKLocalDateTime.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_withHour_normal() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
    for (int i = 0; i < 24; i++) {
        t = t.withHour(i);
        assertEquals(t.getHour(), i);
    }
}
 
Example 10
Source File: TCKLocalDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_withHour_normal() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
    for (int i = 0; i < 24; i++) {
        t = t.withHour(i);
        assertEquals(t.getHour(), i);
    }
}
 
Example 11
Source File: TCKLocalDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_withHour_normal() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
    for (int i = 0; i < 24; i++) {
        t = t.withHour(i);
        assertEquals(t.getHour(), i);
    }
}
 
Example 12
Source File: TCKLocalDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_withHour_normal() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
    for (int i = 0; i < 24; i++) {
        t = t.withHour(i);
        assertEquals(t.getHour(), i);
    }
}
 
Example 13
Source File: TCKLocalDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_withHour_normal() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
    for (int i = 0; i < 24; i++) {
        t = t.withHour(i);
        assertEquals(t.getHour(), i);
    }
}
 
Example 14
Source File: TCKLocalDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_withHour_normal() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
    for (int i = 0; i < 24; i++) {
        t = t.withHour(i);
        assertEquals(t.getHour(), i);
    }
}
 
Example 15
Source File: TCKLocalDateTime.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_withHour_normal() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
    for (int i = 0; i < 24; i++) {
        t = t.withHour(i);
        assertEquals(t.getHour(), i);
    }
}
 
Example 16
Source File: TCKLocalDateTime.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_withHour_normal() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
    for (int i = 0; i < 24; i++) {
        t = t.withHour(i);
        assertEquals(t.getHour(), i);
    }
}
 
Example 17
Source File: Instants.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private static LocalDateTime setTime(LocalDateTime ldt, String time) {
   String [] parts = time.split("\\:");
   ldt = ldt.withHour(Integer.parseInt(parts[0]));
   if(parts.length > 1) {
      ldt = ldt.withMinute(Integer.parseInt(parts[1]));
   }
   if(parts.length > 2) {
      ldt = ldt.withSecond(Integer.parseInt(parts[2]));
   }
   return ldt;
}
 
Example 18
Source File: Axis.java    From charts with Apache License 2.0 4 votes vote down vote up
private List<LocalDateTime> makeDatesEven(List<LocalDateTime> dates, LocalDateTime dateTime) {
    // If the dates contain more dates than just the lower and upper bounds, make the dates in between even.
    if (dates.size() > 2) {
        List<LocalDateTime> evenDates = new ArrayList<>();

        // For each interval, modify the date slightly by a few millis, to make sure they are different days.
        // This is because Axis stores each value and won't update the tick labels, if the value is already known.
        // This happens if you display days and then add a date many years in the future the tick label will still be displayed as day.
        for (int i = 0; i < dates.size(); i++) {
            dateTime = dates.get(i);
            switch (currentInterval.getInterval()) {
                case YEARS:
                    // If its not the first or last date (lower and upper bound), make the year begin with first month and let the months begin with first day.
                    if (i != 0 && i != dates.size() - 1) {
                        dateTime.withMonth(1);
                        dateTime.withDayOfMonth(1);
                    }
                    dateTime.withHour(0);
                    dateTime.withMinute(0);
                    dateTime.withSecond(0);
                    dateTime.withNano(6000000);
                    break;
                case MONTHS:
                    // If its not the first or last date (lower and upper bound), make the months begin with first day.
                    if (i != 0 && i != dates.size() - 1) {
                        dateTime.withDayOfMonth(1);
                    }
                    dateTime.withHour(0);
                    dateTime.withMinute(0);
                    dateTime.withSecond(0);
                    dateTime.withNano(5000000);
                    break;
                case WEEKS:
                    // Make weeks begin with first day of week?
                    dateTime.withHour(0);
                    dateTime.withMinute(0);
                    dateTime.withSecond(0);
                    dateTime.withNano(4000000);
                    break;
                case DAYS:
                    dateTime.withHour(0);
                    dateTime.withMinute(0);
                    dateTime.withSecond(0);
                    dateTime.withNano(3000000);
                    break;
                case HOURS:
                    if (i != 0 && i != dates.size() - 1) {
                        dateTime.withMinute(0);
                        dateTime.withSecond(0);
                    }
                    dateTime.withNano(2000000);
                    break;
                case MINUTES:
                    if (i != 0 && i != dates.size() - 1) {
                        dateTime.withSecond(0);
                    }
                    dateTime.withNano(1000000);
                    break;
                case SECONDS:
                    dateTime.withSecond(0);
                    break;

            }
            evenDates.add(dateTime);
        }

        return evenDates;
    } else {
        return dates;
    }
}