Пример #1
0
  public static void main(String[] args) throws ParseException {

    OffsetDateTime start = OffsetDateTime.parse("2014-06-10T10:45:00+03:00");
    // Takes the time stamp and converts to an OffsetDateTime object
    OffsetDateTime end = OffsetDateTime.parse("2015-06-10T10:50:00+03:00");

    Instant startInst = start.toInstant(); // converts it to an Instant Class object
    Instant endInst = end.toInstant();
    Duration dur =
        Duration.between(startInst, endInst); // calculates the duration between the two instances

    System.out.println("The Period between the two instants is:\n");
    System.out.println(dur.toMillis() + " Millisecs"); // prints the milliseconds
  }
Пример #2
0
 public void test_convertToInstant_furtherAfterLeap() {
   OffsetDateTime odt = OffsetDateTime.of(1980, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC);
   Instant instant = odt.toInstant();
   UtcInstant utc = UtcInstant.ofModifiedJulianDay(MJD_1980, NANOS_PER_SEC);
   assertEquals(rules.convertToInstant(utc), instant);
   assertEquals(rules.convertToUtc(instant), utc);
 }
Пример #3
0
 // -----------------------------------------------------------------------
 // convertToUtc(Instant)/convertToInstant(UtcInstant)
 // -----------------------------------------------------------------------
 public void test_convertToInstant_justBeforeLeap() {
   OffsetDateTime odt = OffsetDateTime.of(1979, 12, 31, 23, 43, 21, 0, ZoneOffset.UTC);
   Instant instant = odt.toInstant();
   UtcInstant utc =
       UtcInstant.ofModifiedJulianDay(MJD_1980 - 1, (SECS_PER_DAY + 1 - 1000) * NANOS_PER_SEC);
   assertEquals(rules.convertToInstant(utc), instant);
   assertEquals(rules.convertToUtc(instant), utc);
 }
Пример #4
0
 public void test_convertToInstant_slsMicros() {
   for (int i = 1; i < 1000; i++) {
     long utcNanos = (SECS_PER_DAY + 1 - 1000) * NANOS_PER_SEC + i * 1000;
     long startSls = (86401 - 1000) * NANOS_PER_SEC;
     long slsNanos = (utcNanos - (utcNanos - startSls) / 1000);
     OffsetDateTime odt =
         OffsetDateTime.of(
             1979, 12, 31, 23, 43, 21, (int) (slsNanos % NANOS_PER_SEC), ZoneOffset.UTC);
     Instant instant = odt.toInstant();
     UtcInstant utc =
         UtcInstant.ofModifiedJulianDay(
             MJD_1980 - 1, (SECS_PER_DAY + 1 - 1000) * NANOS_PER_SEC + i * 1000);
     assertEquals(rules.convertToInstant(utc), instant);
     assertEquals(rules.convertToUtc(instant), utc);
   }
 }
Пример #5
0
 public void test_convertToInstant_slsNanos() {
   for (int i = 1; i < 5005; i++) {
     long utcNanos = (SECS_PER_DAY + 1 - 1000) * NANOS_PER_SEC + i;
     long startSls = (86401 - 1000) * NANOS_PER_SEC;
     long slsNanos = (utcNanos - (utcNanos - startSls) / 1000);
     OffsetDateTime odt =
         OffsetDateTime.of(
             1979, 12, 31, 23, 43, 21, (int) (slsNanos % NANOS_PER_SEC), ZoneOffset.UTC);
     Instant instant = odt.toInstant();
     UtcInstant utc = UtcInstant.ofModifiedJulianDay(MJD_1980 - 1, utcNanos);
     assertEquals(rules.convertToInstant(utc), instant);
     // not all instants can map back to the correct UTC value
     long reverseUtcNanos = startSls + ((slsNanos - startSls) * 1000L) / (1000L - 1);
     assertEquals(
         rules.convertToUtc(instant),
         UtcInstant.ofModifiedJulianDay(MJD_1980 - 1, reverseUtcNanos));
   }
 }
  @Test
  public void shouldReturnJobIfJobExists() throws Exception {
    // given
    ZoneId cet = ZoneId.of("CET");
    OffsetDateTime now = OffsetDateTime.now(cet);
    JobInfo expectedJob = newJobInfo("42", "TEST", fixed(now.toInstant(), cet), "localhost");
    when(jobService.findJob("42")).thenReturn(Optional.of(expectedJob));

    String nowAsString = ISO_OFFSET_DATE_TIME.format(now);
    mockMvc
        .perform(
            MockMvcRequestBuilders.get("/some-microservice/internal/jobs/42")
                .servletPath("/internal/jobs/42"))
        .andExpect(MockMvcResultMatchers.status().is(200))
        .andExpect(MockMvcResultMatchers.jsonPath("$.status").value("OK"))
        .andExpect(MockMvcResultMatchers.jsonPath("$.messages").isArray())
        .andExpect(MockMvcResultMatchers.jsonPath("$.jobType").value("TEST"))
        .andExpect(MockMvcResultMatchers.jsonPath("$.hostname").value("localhost"))
        .andExpect(MockMvcResultMatchers.jsonPath("$.started").value(nowAsString))
        .andExpect(MockMvcResultMatchers.jsonPath("$.stopped").value(""))
        .andExpect(MockMvcResultMatchers.jsonPath("$.lastUpdated").value(nowAsString))
        .andExpect(
            MockMvcResultMatchers.jsonPath("$.jobUri")
                .value("http://localhost/some-microservice/internal/jobs/42"))
        .andExpect(MockMvcResultMatchers.jsonPath("$.links").isArray())
        .andExpect(
            MockMvcResultMatchers.jsonPath("$.links[0].href")
                .value("http://localhost/some-microservice/internal/jobs/42"))
        .andExpect(
            MockMvcResultMatchers.jsonPath("$.links[1].href")
                .value("http://localhost/some-microservice/internal/jobdefinitions/TEST"))
        .andExpect(
            MockMvcResultMatchers.jsonPath("$.links[2].href")
                .value("http://localhost/some-microservice/internal/jobs"))
        .andExpect(
            MockMvcResultMatchers.jsonPath("$.links[3].href")
                .value("http://localhost/some-microservice/internal/jobs?type=TEST"))
        .andExpect(MockMvcResultMatchers.jsonPath("$.runtime").value(""))
        .andExpect(MockMvcResultMatchers.jsonPath("$.state").value("Running"));
    verify(jobService).findJob("42");
  }