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

The following examples show how to use java.time.ZonedDateTime#withDayOfMonth() . 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: BloodPressureResourceIntTest.java    From 21-points with Apache License 2.0 6 votes vote down vote up
@Test
@Transactional
public void getBloodPressureByMonth() throws Exception {
    ZonedDateTime now = ZonedDateTime.now();
    ZonedDateTime firstOfMonth = now.withDayOfMonth(1);
    ZonedDateTime firstDayOfLastMonth = firstOfMonth.minusMonths(1);
    createBloodPressureByMonth(firstOfMonth, firstDayOfLastMonth);

    // create security-aware mockMvc
    restBloodPressureMockMvc = MockMvcBuilders
        .webAppContextSetup(context)
        .apply(springSecurity())
        .build();

    DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM");

    // Get the points for last week
    restBloodPressureMockMvc.perform(get("/api/bp-by-month/{yearAndMonth}", fmt.format(firstDayOfLastMonth))
        .with(user("user").roles("USER")))
        .andDo(print())
        .andExpect(status().isOk())
        .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.period").value(fmt.format(firstDayOfLastMonth)))
        .andExpect(jsonPath("$.readings.[*].systolic").value(hasItem(130)))
        .andExpect(jsonPath("$.readings.[*].diastolic").value(hasItem(90)));
}
 
Example 2
Source File: WeightResourceIntTest.java    From 21-points with Apache License 2.0 6 votes vote down vote up
@Test
@Transactional
public void getByLastMonth() throws Exception {
    ZonedDateTime now = ZonedDateTime.now();
    ZonedDateTime firstOfMonth = now.withDayOfMonth(1);
    ZonedDateTime firstDayOfLastMonth = firstOfMonth.minusMonths(1);
    createByMonth(firstOfMonth, firstDayOfLastMonth);

    // create security-aware mockMvc
    restWeightMockMvc = MockMvcBuilders
        .webAppContextSetup(context)
        .apply(springSecurity())
        .build();

    DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM");

    // Get the points for last week
    restWeightMockMvc.perform(get("/api/weight-by-month/{yearAndMonth}", fmt.format(firstDayOfLastMonth))
        .with(user("user").roles("USER")))
        .andDo(print())
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
        .andExpect(jsonPath("$.period").value(fmt.format(firstDayOfLastMonth)))
        .andExpect(jsonPath("$.weighIns.[*].weight").value(hasItem(206D)));
}
 
Example 3
Source File: TCKZonedDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(30);
    assertEquals(test, base);
}
 
Example 4
Source File: TCKZonedDateTime.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withDayOfMonth(15), ZONE_0100));
}
 
Example 5
Source File: TCKZonedDateTime.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(30);
    assertEquals(test, base);
}
 
Example 6
Source File: TCKZonedDateTime.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withDayOfMonth(15), ZONE_0100));
}
 
Example 7
Source File: TCKZonedDateTime.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(30);
    assertEquals(test, base);
}
 
Example 8
Source File: TCKZonedDateTime.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withDayOfMonth(15), ZONE_0100));
}
 
Example 9
Source File: TCKZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withDayOfMonth(15), ZONE_0100));
}
 
Example 10
Source File: TCKZonedDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(30);
    assertEquals(test, base);
}
 
Example 11
Source File: TCKZonedDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withDayOfMonth(15), ZONE_0100));
}
 
Example 12
Source File: ZonedDateTimeAxis.java    From constellation with Apache License 2.0 4 votes vote down vote up
/**
 * Makes datetimes even, in the sense of that years always begin in January,
 * months always begin on the 1st and days always at midnight.
 *
 * @param dateTimes The list of dates.
 * @return The new list of dates.
 */
private List<ZonedDateTime> makeDateTimesEven(final List<ZonedDateTime> dateTimes) {
    // if the dates contain more dates than just the lower and upper bounds, make the dates in between even.
    if (dateTimes.size() > 2) {
        List<ZonedDateTime> evenDateTimes = 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 < dateTimes.size(); i++) {
            ZonedDateTime evenDateTime = dateTimes.get(i);
            switch (actualInterval.interval) {
                case YEARS:
                    // if it's 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 != dateTimes.size() - 1) {
                        evenDateTime = evenDateTime.withMonth(0);
                        evenDateTime = evenDateTime.withDayOfMonth(1);
                    }
                    evenDateTime = evenDateTime.withHour(0);
                    evenDateTime = evenDateTime.withMinute(0);
                    evenDateTime = evenDateTime.withSecond(0);
                    evenDateTime = evenDateTime.withNano(6 * TemporalConstants.NANOSECONDS_IN_MILLISECOND);
                    break;
                case MONTHS:
                    // if it's not the first or last date (lower and upper bound), make the months begin with first day.
                    if (i != 0 && i != dateTimes.size() - 1) {
                        evenDateTime = evenDateTime.withDayOfMonth(1);
                    }
                    evenDateTime = evenDateTime.withHour(0);
                    evenDateTime = evenDateTime.withMinute(0);
                    evenDateTime = evenDateTime.withSecond(0);
                    evenDateTime = evenDateTime.withNano(5 * TemporalConstants.NANOSECONDS_IN_MILLISECOND);
                    break;
                case WEEKS:
                    // make weeks begin with first day of week?
                    evenDateTime = evenDateTime.withHour(0);
                    evenDateTime = evenDateTime.withMinute(0);
                    evenDateTime = evenDateTime.withSecond(0);
                    evenDateTime = evenDateTime.withNano(4 * TemporalConstants.NANOSECONDS_IN_MILLISECOND);
                    break;
                case DAYS:
                    evenDateTime = evenDateTime.withHour(0);
                    evenDateTime = evenDateTime.withMinute(0);
                    evenDateTime = evenDateTime.withSecond(0);
                    evenDateTime = evenDateTime.withNano(3 * TemporalConstants.NANOSECONDS_IN_MILLISECOND);
                    break;
                case HOURS:
                    if (i != 0 && i != dateTimes.size() - 1) {
                        evenDateTime = evenDateTime.withMinute(0);
                        evenDateTime = evenDateTime.withSecond(0);
                    }
                    evenDateTime = evenDateTime.withNano(2 * TemporalConstants.NANOSECONDS_IN_MILLISECOND);
                    break;
                case MINUTES:
                    if (i != 0 && i != dateTimes.size() - 1) {
                        evenDateTime = evenDateTime.withSecond(0);
                    }
                    evenDateTime = evenDateTime.withNano(1 * TemporalConstants.NANOSECONDS_IN_MILLISECOND);
                    break;
                case SECONDS:
                    evenDateTime = evenDateTime.withNano(0 * TemporalConstants.NANOSECONDS_IN_MILLISECOND);
                    break;
                default:
                    break;
            }
            evenDateTimes.add(evenDateTime);
        }

        return evenDateTimes;
    } else {
        return dateTimes;
    }
}
 
Example 13
Source File: TCKZonedDateTime.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(30);
    assertEquals(test, base);
}
 
Example 14
Source File: TCKZonedDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(30);
    assertEquals(test, base);
}
 
Example 15
Source File: TCKZonedDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(30);
    assertEquals(test, base);
}
 
Example 16
Source File: TCKZonedDateTime.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withDayOfMonth(15), ZONE_0100));
}
 
Example 17
Source File: TCKZonedDateTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(30);
    assertEquals(test, base);
}
 
Example 18
Source File: TCKZonedDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withDayOfMonth(15), ZONE_0100));
}
 
Example 19
Source File: TCKZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withDayOfMonth(15), ZONE_0100));
}
 
Example 20
Source File: TCKZonedDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withDayOfMonth_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withDayOfMonth(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withDayOfMonth(15), ZONE_0100));
}