public static void main(String[] args) {
    LocalDateTime lDT = LocalDateTime.of(LocalDate.of(2016, 01, 17), LocalTime.of(23, 11, 25));

    System.out.println("The date and time is : " + lDT.toString());
    System.out.println("The strict date is :" + lDT.toLocalDate().toString());
    System.out.println("The strict time is :" + lDT.toLocalTime().toString());
  }
Esempio n. 2
0
  @Test
  public void timeout() {
    Jcl jcl =
        JclFactory.compileJcl(
            JOB
                + "## run at 2016-2-10 18:24 timeout 1 minute\n"
                + "## run at 2016/2/10 18:24 timeout 1 hour\n"
                + "## run every minute timeout minute\n"
                + "## run every 10 minutes timeout 5 minutes\n");
    test(jcl);

    System.out.println(jcl.getSchedule().replace("><", ">\n<"));

    assertSame(JclType.SCHEDULABLE, jcl.getType());

    LocalDateTime dt = LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES);
    String now = dt.toLocalDate().toString() + " " + dt.toLocalTime().toString();

    assertEquals(
        "Schedule",
        "<schedule>"
            + "<once at=\"2016-02-10 18:24\" timeout=\"1 minute\"/>"
            + "<once at=\"2016-02-10 18:24\" timeout=\"1 hour\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"1 minute\" timeout=\"1 minute\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"10 minute\" timeout=\"5 minute\"/>"
            + "</schedule>",
        jcl.getSchedule());
  }
 @Test
 public void testAsLocalDateTime() {
   LocalDateTime dateTime = LocalDateTime.now();
   long packed = pack(dateTime.toLocalDate(), dateTime.toLocalTime());
   LocalDateTime upacked = asLocalDateTime(packed);
   assertEquals(dateTime.getDayOfYear(), upacked.getDayOfYear());
   assertEquals(dateTime.getHour(), upacked.getHour());
   assertEquals(dateTime.getMinute(), upacked.getMinute());
   assertEquals(dateTime.getSecond(), upacked.getSecond());
 }
  private static void useLocalDate() {
    LocalDate date = LocalDate.of(2014, 3, 18);
    int year = date.getYear(); // 2014
    Month month = date.getMonth(); // MARCH
    int day = date.getDayOfMonth(); // 18
    DayOfWeek dow = date.getDayOfWeek(); // TUESDAY
    int len = date.lengthOfMonth(); // 31 (days in March)
    boolean leap = date.isLeapYear(); // false (not a leap year)
    System.out.println(date);

    int y = date.get(ChronoField.YEAR);
    int m = date.get(ChronoField.MONTH_OF_YEAR);
    int d = date.get(ChronoField.DAY_OF_MONTH);

    LocalTime time = LocalTime.of(13, 45, 20); // 13:45:20
    int hour = time.getHour(); // 13
    int minute = time.getMinute(); // 45
    int second = time.getSecond(); // 20
    System.out.println(time);

    LocalDateTime dt1 = LocalDateTime.of(2014, Month.MARCH, 18, 13, 45, 20); // 2014-03-18T13:45
    LocalDateTime dt2 = LocalDateTime.of(date, time);
    LocalDateTime dt3 = date.atTime(13, 45, 20);
    LocalDateTime dt4 = date.atTime(time);
    LocalDateTime dt5 = time.atDate(date);
    System.out.println(dt1);

    LocalDate date1 = dt1.toLocalDate();
    System.out.println(date1);
    LocalTime time1 = dt1.toLocalTime();
    System.out.println(time1);

    Instant instant = Instant.ofEpochSecond(44 * 365 * 86400);
    Instant now = Instant.now();

    Duration d1 = Duration.between(LocalTime.of(13, 45, 10), time);
    Duration d2 = Duration.between(instant, now);
    System.out.println(d1.getSeconds());
    System.out.println(d2.getSeconds());

    Duration threeMinutes = Duration.of(3, ChronoUnit.MINUTES);
    System.out.println(threeMinutes);

    JapaneseDate japaneseDate = JapaneseDate.from(date);
    System.out.println(japaneseDate);
  }
Esempio n. 5
0
  @Test
  public void runEvery() {
    Jcl jcl =
        JclFactory.compileJcl(
            JOB
                + "## run every minute\n"
                + "## run every 10 minutes\n"
                + "## run every hour\n"
                + "## run every 3 hours\n"
                + "## run every day\n"
                + "## run every 2 days\n"
                + "## run every 2 day\n"
                // retry on failure after 1 hour
                + "## run every day retry 1 hour\n"
                + "## run every day retry 1 hour maximum 3 times\n"
                + "## run every day retry every 1 hour\n"
                + "## run every day retry every 1 hour maximum 3\n"
                // Between
                + "## run every hour between 00:00 and 06:00\n"
                + "## run every hour between 00:00 and 06:00 retry 10 minutes maximum 3 times\n"
                + "## run every hour between 21:00 and 03:00\n"
                + "## run every hour between 21:00 and 03:00 retry 10 minutes maximum 3 times\n");
    test(jcl);

    System.out.println(jcl.getSchedule().replace("><", ">\n<"));

    assertSame(JclType.SCHEDULABLE, jcl.getType());

    LocalDateTime dt = LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES);
    String now = dt.toLocalDate().toString() + " " + dt.toLocalTime().toString();

    assertEquals(
        "Schedule",
        "<schedule>"
            + "<repeat next=\""
            + now
            + "\" step=\"1 minute\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"10 minute\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"1 hour\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"3 hour\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"1 day\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"2 day\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"2 day\"/>"
            // retry on failure after 1 hour
            + "<repeat next=\""
            + now
            + "\" step=\"1 day\" retry=\"1 hour\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"1 day\" retry=\"1 hour\" max=\"3\"/>"
            // same but with every keyword
            + "<repeat next=\""
            + now
            + "\" step=\"1 day\" retry=\"1 hour\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"1 day\" retry=\"1 hour\" max=\"3\"/>"
            // Between
            + "<repeat next=\""
            + now
            + "\" step=\"1 hour\" between=\"00:00-06:00\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"1 hour\" retry=\"10 minute\" max=\"3\" between=\"00:00-06:00\"/>"
            // Between 2100-0300 crossing midnight
            + "<repeat next=\""
            + now
            + "\" step=\"1 hour\" between=\"21:00-03:00\"/>"
            // Between 2100-0300 crossing midnight retry 10 minutes max 3
            + "<repeat next=\""
            + now
            + "\" step=\"1 hour\" retry=\"10 minute\" max=\"3\" between=\"21:00-03:00\"/>"
            + "</schedule>",
        jcl.getSchedule());
  }