예제 #1
0
 // -----------------------------------------------------------------------
 // isSupportedBy(TemporalAccessor temporal) and getFrom(TemporalAccessor temporal)
 // -----------------------------------------------------------------------
 @DataProvider(name = "fieldAndAccessor")
 Object[][] data_fieldAndAccessor() {
   return new Object[][] {
     {YEAR, LocalDate.of(2000, 2, 29), true, 2000},
     {YEAR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 2000},
     {MONTH_OF_YEAR, LocalDate.of(2000, 2, 29), true, 2},
     {MONTH_OF_YEAR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 2},
     {DAY_OF_MONTH, LocalDate.of(2000, 2, 29), true, 29},
     {DAY_OF_MONTH, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 29},
     {DAY_OF_YEAR, LocalDate.of(2000, 2, 29), true, 60},
     {DAY_OF_YEAR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 60},
     {HOUR_OF_DAY, LocalTime.of(5, 4, 3, 200), true, 5},
     {HOUR_OF_DAY, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 5},
     {MINUTE_OF_DAY, LocalTime.of(5, 4, 3, 200), true, 5 * 60 + 4},
     {MINUTE_OF_DAY, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 5 * 60 + 4},
     {MINUTE_OF_HOUR, LocalTime.of(5, 4, 3, 200), true, 4},
     {MINUTE_OF_HOUR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 4},
     {SECOND_OF_DAY, LocalTime.of(5, 4, 3, 200), true, 5 * 3600 + 4 * 60 + 3},
     {SECOND_OF_DAY, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 5 * 3600 + 4 * 60 + 3},
     {SECOND_OF_MINUTE, LocalTime.of(5, 4, 3, 200), true, 3},
     {SECOND_OF_MINUTE, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 3},
     {NANO_OF_SECOND, LocalTime.of(5, 4, 3, 200), true, 200},
     {NANO_OF_SECOND, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 200},
     {YEAR, LocalTime.of(5, 4, 3, 200), false, -1},
     {MONTH_OF_YEAR, LocalTime.of(5, 4, 3, 200), false, -1},
     {DAY_OF_MONTH, LocalTime.of(5, 4, 3, 200), false, -1},
     {DAY_OF_YEAR, LocalTime.of(5, 4, 3, 200), false, -1},
     {HOUR_OF_DAY, LocalDate.of(2000, 2, 29), false, -1},
     {MINUTE_OF_DAY, LocalDate.of(2000, 2, 29), false, -1},
     {MINUTE_OF_HOUR, LocalDate.of(2000, 2, 29), false, -1},
     {SECOND_OF_DAY, LocalDate.of(2000, 2, 29), false, -1},
     {SECOND_OF_MINUTE, LocalDate.of(2000, 2, 29), false, -1},
     {NANO_OF_SECOND, LocalDate.of(2000, 2, 29), false, -1},
   };
 }
  @Test
  public void checkRulePassengerTime() {
    List<PassengerGenerationRule> workDayRulesOfGagarina = new ArrayList<>();
    workDayRulesOfGagarina.add(
        PassengerGenerationRule.of(8, LocalTime.of(6, 0), LocalTime.of(6, 0), LocalTime.of(0, 15)));
    //        workDayRulesOfGagarina.add(PassengerGenerationRule.of(
    //                4, LocalTime.of(9, 0), LocalTime.of(13, 0), LocalTime.of(0, 17))
    //        );
    //        workDayRulesOfGagarina.add(PassengerGenerationRule.of(
    //                2, LocalTime.of(13, 0), LocalTime.of(16, 0), LocalTime.of(0, 17))
    //        );
    //        workDayRulesOfGagarina.add(PassengerGenerationRule.of(
    //                8, LocalTime.of(16, 0), LocalTime.of(19, 0), LocalTime.of(0, 15))
    //        );
    //        workDayRulesOfGagarina.add(PassengerGenerationRule.of(
    //                4, LocalTime.of(19, 0), LocalTime.of(23, 0), LocalTime.of(0, 15))
    //        );

    PassengerGenerationRuleList item =
        PassengerGenerationRuleList.of(HOLIDAY, workDayRulesOfGagarina);

    Set<ConstraintViolation<PassengerGenerationRuleList>> constraintViolations =
        validator.validate(item, ImitationSourceSequence.class);
    constraintViolations.forEach(System.out::println);

    assertEquals(1, constraintViolations.size());
    assertEquals(
        "{incorrect rule passenger generation time}",
        constraintViolations.iterator().next().getMessage());
  }
  @RequestMapping(value = "/insertRoute.do", method = RequestMethod.POST)
  public ModelAndView insertRoute(
      @RequestParam(value = ROUTE_NUMBER) String routeNumber,
      @RequestParam(value = STATION_LEAVING_STATION) String leavingStation,
      @RequestParam(value = STATION_ARRIVAL_STATION) String arrivalStation,
      @RequestParam(value = STATION_LEAVING_HOUR) String leavingHH,
      @RequestParam(value = STATION_LEAVING_MINUTE) String leavingMM,
      @RequestParam(value = STATION_ARRIVAL_HOUR) String arrivalHH,
      @RequestParam(value = STATION_ARRIVAL_MINUTE) String arrivalMM) {

    Integer routeNum = routeNumberCheck(routeNumber);
    if (routeNum != null) {
      Route route = new Route();
      route.setRouteNumber(routeNum);
      route.setLeavingStation(leavingStation);
      route.setArrivalStation(arrivalStation);
      route.setLeavingTime(LocalTime.of(Integer.parseInt(leavingHH), Integer.parseInt(leavingMM)));
      route.setArrivalTime(LocalTime.of(Integer.parseInt(arrivalHH), Integer.parseInt(arrivalMM)));
      if (iRouteService.insertRoute(route)) {
        return new ModelAndView(PAGE_MAIN, INFO, route.toString() + " added");
      } else {
        return new ModelAndView(PAGE_INSERT_ROUTE, INFO, route.toString() + " didn't add");
      }
    } else {
      return new ModelAndView(PAGE_INSERT_ROUTE, INFO, "Wrong route number format");
    }
  }
예제 #4
0
 @Test(groups = {"implementation"})
 public void factory_time_4ints_singletons() {
   for (int i = 0; i < 24; i++) {
     LocalTime test1 = LocalTime.of(i, 0, 0, 0);
     LocalTime test2 = LocalTime.of(i, 0, 0, 0);
     assertSame(test1, test2);
   }
 }
  @Test
  public void checkRulePassengerIntersection() {
    List<PassengerGenerationRule> workDayRulesOfGagarina = new ArrayList<>();
    workDayRulesOfGagarina.add(
        PassengerGenerationRule.of(
            8, LocalTime.of(6, 0), LocalTime.of(9, 50), LocalTime.of(0, 15)));
    workDayRulesOfGagarina.add(
        PassengerGenerationRule.of(
            8, LocalTime.of(5, 0), LocalTime.of(8, 50), LocalTime.of(0, 20)));
    workDayRulesOfGagarina.add(
        PassengerGenerationRule.of(
            8, LocalTime.of(22, 0), LocalTime.of(4, 50), LocalTime.of(0, 20)));

    PassengerGenerationRuleList item =
        PassengerGenerationRuleList.of(HOLIDAY, workDayRulesOfGagarina);

    Set<ConstraintViolation<PassengerGenerationRuleList>> constraintViolations =
        validator.validate(item, ImitationSourceSequence.class);
    constraintViolations.forEach(System.out::println);

    assertEquals(1, constraintViolations.size());
    assertEquals(
        "{rule passenger generation is intersection}",
        constraintViolations.iterator().next().getMessage());
  }
예제 #6
0
 public static void main(String[] args) {
   List<UserMeal> mealList =
       Arrays.asList(
           new UserMeal(LocalDateTime.of(2015, Month.MAY, 30, 10, 0), "Завтрак", 500),
           new UserMeal(LocalDateTime.of(2015, Month.MAY, 30, 13, 0), "Обед", 1000),
           new UserMeal(LocalDateTime.of(2015, Month.MAY, 30, 20, 0), "Ужин", 500),
           new UserMeal(LocalDateTime.of(2015, Month.MAY, 31, 10, 0), "Завтрак", 1000),
           new UserMeal(LocalDateTime.of(2015, Month.MAY, 31, 13, 0), "Обед", 500),
           new UserMeal(LocalDateTime.of(2015, Month.MAY, 31, 20, 0), "Ужин", 510));
   getFilteredWithExceeded(mealList, LocalTime.of(7, 0), LocalTime.of(12, 0), 2000);
   //        .toLocalDate();
   //        .toLocalTime();
 }
예제 #7
0
  public void setAttendanceStatusType(AttendanceStatusType statusType) {
    if (statusType.compareTo(AttendanceStatusType.PRESENT) == 0) {
      if (getWorkTimeForDay().compareTo(LocalTime.of(4, 0)) < 0)
        statusType = AttendanceStatusType.ABSENT;
      else if (getWorkTimeForDay().compareTo(LocalTime.of(6, 0)) < 0)
        statusType = AttendanceStatusType.HALF_DAY;
    }

    if (statusType.compareTo(AttendanceStatusType.ABSENT) == 0) {
      if (getCurrentDate().getDayOfWeek() == DayOfWeek.SATURDAY
          || getCurrentDate().getDayOfWeek() == DayOfWeek.SUNDAY)
        statusType = AttendanceStatusType.WEEKEND_HOLIDAY;
    }
    this.attendanceStatusType = statusType;
  }
예제 #8
0
  @Override
  public List<Notice> list(String status, LocalDate fromDate, LocalDate toDate, String dongName)
      throws OperationalException {

    try {

      List<Criterion> criteriaList = new ArrayList<>();

      if (!StringUtils.isBlank(status) && !status.equalsIgnoreCase(ALL)) {
        criteriaList.add(Restrictions.eq(STATUS, status));
      }
      if (!StringUtils.isBlank(dongName) && !dongName.equalsIgnoreCase(ALL)) {
        criteriaList.add(Restrictions.eq("dongName", dongName));
      }
      if (fromDate != null) {
        LocalTime time = LocalTime.MIDNIGHT;
        LocalDateTime fromtime = LocalDateTime.of(fromDate, time);
        criteriaList.add(Restrictions.ge(CREATIONDATE, fromtime));
      }
      if (toDate != null) {
        LocalTime time = LocalTime.of(23, 59, 59);
        LocalDateTime totime = LocalDateTime.of(toDate, time);
        criteriaList.add(Restrictions.le(CREATIONDATE, totime));
      }
      criteriaList.add(Restrictions.ne(STATUS, NoticeStatus.DELETED.name()));
      return super.findByCriteria(Notice.class, criteriaList, Order.desc(CREATIONDATE));

    } catch (Exception e) {
      LOGGER.error("list: Exception ", e);
      throw new OperationalException(
          HttpConstants.INTERNAL_SERVER_ERROR,
          ResponseConstants.ERROR_FETCHING_FROM_DB,
          HttpStatus.INTERNAL_SERVER_ERROR);
    }
  }
예제 #9
0
  public static void main(String[] args) {
    LocalDate hoje = LocalDate.now();
    System.out.println(hoje);

    LocalDate olimpiadasRio = LocalDate.of(2016, Month.JUNE, 5);
    System.out.println(olimpiadasRio);

    int dias = olimpiadasRio.getDayOfYear() - hoje.getDayOfYear();
    System.out.println(dias + " dias para as Olímpiadas no Rio!");

    Period periodo = Period.between(hoje, olimpiadasRio);
    System.out.println(periodo.getMonths() + " meses e " + periodo.getDays() + " dias.");

    DateTimeFormatter formatador = DateTimeFormatter.ofPattern("dd/MM/yyyy");
    String valorFormatado = olimpiadasRio.format(formatador);
    System.out.println(valorFormatado);

    System.out.println(" --- Medida de tempo ---");

    DateTimeFormatter formatadorComHoras = DateTimeFormatter.ofPattern("dd/MM/yyyy hh:mm:ss");
    LocalDateTime agora = LocalDateTime.now();
    System.out.println(agora);
    System.out.println(agora.format(formatadorComHoras));

    LocalTime intervalo = LocalTime.of(12, 30);
    System.out.println(intervalo);
  }
  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());
  }
  public Object getObject(ExecutionContext ec, ResultSet resultSet, int[] exprIndex) {
    if (exprIndex == null) {
      return null;
    }

    Object datastoreValue = getDatastoreMapping(0).getObject(resultSet, exprIndex[0]);
    if (datastoreValue == null) {
      return null;
    }

    if (datastoreValue instanceof String) {
      TypeConverter conv =
          ec.getNucleusContext()
              .getTypeManager()
              .getTypeConverterForType(LocalTime.class, String.class);
      if (conv != null) {
        return conv.toMemberType(datastoreValue);
      } else {
        throw new NucleusUserException("This type doesn't support persistence as a String");
      }
    } else if (datastoreValue instanceof Time) {
      Time time = (Time) datastoreValue;
      Calendar cal = Calendar.getInstance();
      cal.setTime(time);
      LocalTime localTime =
          LocalTime.of(
              cal.get(Calendar.HOUR_OF_DAY),
              cal.get(Calendar.MINUTE),
              cal.get(Calendar.SECOND),
              cal.get(Calendar.MILLISECOND) * 1000000);
      return localTime;
    } else {
      return null;
    }
  }
/** @author <a href="mailto:[email protected]">Lennart J&ouml;relid</a>, jGuru Europe AB */
public class LocalDateTimeAdapterTest {

  private String transportForm = "2015-04-25T15:40:00";
  private LocalDateTime objectForm =
      LocalDateTime.of(LocalDate.of(2015, Month.APRIL, 25), LocalTime.of(15, 40, 0));
  private LocalDateTimeAdapter unitUnderTest = new LocalDateTimeAdapter();

  @Test
  public void validateConvertingToTransportForm() throws Exception {

    // Assemble

    // Act
    final String result = unitUnderTest.marshal(objectForm);
    // System.out.println("Got: " + result);

    // Assert
    Assert.assertNull(unitUnderTest.marshal(null));
    Assert.assertEquals(transportForm, result);
  }

  @Test
  public void validateConvertingFromTransportForm() throws Exception {

    // Assemble

    // Act
    final LocalDateTime result = unitUnderTest.unmarshal(transportForm);

    // Assert
    Assert.assertNull(unitUnderTest.unmarshal(null));
    Assert.assertEquals(objectForm, result);
  }
}
예제 #13
0
 @Test(groups = {"implementation"})
 public void factory_ofNanoOfDay_singletons() {
   for (int i = 0; i < 24; i++) {
     LocalTime test1 = LocalTime.ofNanoOfDay(i * 1000000000L * 60L * 60L);
     LocalTime test2 = LocalTime.of(i, 0);
     assertSame(test1, test2);
   }
 }
 @Test
 public void test_isAfterOrEqual_assertion_error_message() {
   try {
     assertThat(LocalTime.of(3, 0, 5)).isAfterOrEqualTo(LocalTime.of(3, 3, 3));
   } catch (AssertionError e) {
     assertThat(e)
         .hasMessage(
             format(
                 "%n"
                     + "Expecting:%n"
                     + "  <03:00:05>%n"
                     + "to be after or equals to:%n"
                     + "  <03:03:03>"));
     return;
   }
   fail("Should have thrown AssertionError");
 }
예제 #15
0
  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);
  }
 @Before
 public void setUp() throws Exception {
   mockIbClient = mock(InteractiveBrokersClientInterface.class);
   InteractiveBrokersClient.setMockInteractiveBrokersClient(
       mockIbClient, ibHost, ibPort, ibClientId);
   strategy = spy(EODTradingStrategy.class);
   strategy.timeToPlaceOrders = LocalTime.of(12, 40, 0);
   strategy.marketCloseTime = LocalTime.of(13, 0);
   strategy.ibHost = ibHost;
   strategy.ibPort = ibPort;
   strategy.ibClientId = ibClientId;
   strategy.entryOrderType = TradeOrder.Type.MARKET_ON_CLOSE;
   strategy.exitOrderType = TradeOrder.Type.MARKET_ON_OPEN;
   strategy.exitSeconds = 0;
   propFile = Paths.get(getClass().getResource("/eod.test.properties").toURI()).toString();
   doReturn(mockReportGenerator).when(strategy).getReportGenerator(any(String.class));
 }
  @Test
  public void testGetNextBusinessDay_Satruday() {
    ZonedDateTime ldt = ZonedDateTime.of(2016, 2, 27, 6, 45, 55, 0, ZoneId.systemDefault());
    ZonedDateTime expectedDatetime =
        ZonedDateTime.of(2016, 2, 29, 6, 30, 2, 0, ZoneId.systemDefault());
    strategy.exitTime = LocalTime.of(6, 30, 2);

    assertEquals(expectedDatetime, strategy.getNextBusinessDay(ldt));
  }
 @Test
 public void testInitProps() {
   strategy.initProps(propFile);
   assertEquals("localhost", strategy.ibHost);
   assertEquals(7999, strategy.ibPort);
   assertEquals(1, strategy.ibClientId);
   assertEquals(1000, strategy.orderSizeInDollars);
   assertEquals(LocalTime.of(12, 40), strategy.timeToPlaceOrders);
   assertEquals(LocalTime.of(13, 0), strategy.marketCloseTime);
   assertEquals(LocalTime.of(6, 30, 2), strategy.exitTime);
   assertEquals(2, strategy.longShortPairMap.size());
   assertEquals(new StockTicker("SPY"), strategy.longShortPairMap.get(new StockTicker("QQQ")));
   assertEquals(new StockTicker("IWM"), strategy.longShortPairMap.get(new StockTicker("DIA")));
   assertEquals("/some/test/dir/", strategy.strategyDirectory);
   assertEquals(TradeOrder.Type.MARKET_ON_CLOSE, strategy.entryOrderType);
   assertEquals(TradeOrder.Type.MARKET, strategy.exitOrderType);
   assertEquals(3, strategy.exitSeconds);
 }
예제 #19
0
  @Test
  public void parseLogStatement_INFO() {
    LogStatement log = lineParser.parseLogStatement(INFO_LOG);

    assertEquals(LocalTime.of(1, 55, 16), log.getTime());
    assertEquals(Level.INFO, log.getLevel());
    assertEquals(new Clazz("com.web.seam.action.AuthenticatorImpl"), log.getClazz());
    assertEquals("Login successfull for user: [email protected]", log.getMessage());
  }
  private Boolean validateInput() {
    Boolean validation = true;

    // Check if inputs are null or empty
    if (_durationTextField.getText().length() == 0) {
      _durationTextField.setStyle("-fx-text-box-border: red;");
      validation = false;
    } else {
      _durationTextField.setStyle("-fx-text-box-border: lightgrey;");
    }

    if (_datePicker.getValue() == null) {
      _datePicker.setStyle("-fx-date-picker-border: red;");
      validation = false;
    } else {
      _datePicker.setStyle("-fx-date-picker-border: lightgrey;");
    }

    if (_startTimeTextField.getText().length() == 0) {
      _startTimeTextField.setStyle("-fx-text-box-border: red;");
      validation = false;
    } else {
      _startTimeTextField.setStyle("-fx-text-box-border: lightgrey;");
    }

    // check if inputs are matching the given regex
    if (validation) {
      if (_durationTextField.getText().matches("(\\d*)")) {
        _duration = Integer.parseInt(_durationTextField.getText());
        _durationTextField.setStyle("-fx-text-box-border:  lightgrey;");
      } else {
        _durationTextField.setStyle("-fx-text-box-border: red;");
        validation = false;
      }

      // define Regex: 0-24h, 0-59min, 0-69sek
      if (_startTimeTextField.getText().matches("([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])")) {
        _localDate = _datePicker.getValue();
        String[] times = _startTimeTextField.getText().split(":");
        _localTime =
            LocalTime.of(
                Integer.parseInt(times[0]), Integer.parseInt(times[1]), Integer.parseInt(times[2]));
        _startTimeTextField.setStyle("-fx-text-box-border: lightgrey;");
      } else {
        _startTimeTextField.setStyle("-fx-text-box-border: red;");
        validation = false;
      }
    }

    if (_allTeamsTableView.getSelectionModel().getSelectedItem() == null
        || _allTeamsOpponentTableView.getSelectionModel().getSelectedItem() == null) {
      validation = false;
    }

    return validation;
  }
예제 #21
0
  public static void main(String[] args) {
    // java 7 Automatic resource management
    try (ConfigurableApplicationContext appCtx =
        new ClassPathXmlApplicationContext("spring/spring-app.xml", "spring/mock.xml")) {
      System.out.println(Arrays.toString(appCtx.getBeanDefinitionNames()));
      AdminRestController adminUserController = appCtx.getBean(AdminRestController.class);
      System.out.println(
          adminUserController.create(
              new User(1, "userName", "email", "password", 2005, Role.ROLE_ADMIN)));
      System.out.println();

      UserMealRestController mealController = appCtx.getBean(UserMealRestController.class);
      List<UserMealWithExceed> filteredMealsWithExceeded =
          mealController.getBetween(
              LocalDate.of(2015, Month.MAY, 30), LocalTime.of(7, 0),
              LocalDate.of(2015, Month.MAY, 31), LocalTime.of(11, 0));
      filteredMealsWithExceeded.forEach(System.out::println);
    }
  }
  @Test
  public void checkRulePassengerMaxSize() {
    List<PassengerGenerationRule> workDayRulesOfGagarina = new ArrayList<>();
    for (int i = 0; i < 51; i++) {
      workDayRulesOfGagarina.add(
          PassengerGenerationRule.of(
              8, LocalTime.of(6, 0), LocalTime.of(9, 50), LocalTime.of(0, 15)));
    }

    PassengerGenerationRuleList item =
        PassengerGenerationRuleList.of(HOLIDAY, workDayRulesOfGagarina);

    Set<ConstraintViolation<PassengerGenerationRuleList>> constraintViolations =
        validator.validate(item, ImitationSourceSequence.class);
    constraintViolations.forEach(System.out::println);

    assertEquals(1, constraintViolations.size());
    assertEquals(
        "size must be between 2 and 50", constraintViolations.iterator().next().getMessage());
  }
예제 #23
0
 public static void main(String[] args) {
   LocalDate date = LocalDate.of(2015, Month.JULY, 6);
   LocalTime time = LocalTime.of(15, 25);
   LocalDateTime dateTime = LocalDateTime.of(date, time);
   printSectionName("LocalDateTime");
   System.out.println(dateTime);
   System.out.println(dateTime.minusDays(1));
   System.out.println(dateTime.minusHours(5));
   System.out.println(dateTime.minusSeconds(7));
   printDelimiterString();
 }
예제 #24
0
  static void f2() {
    LocalTime time = LocalTime.of(20, 30);
    int hour = time.getHour(); // 20
    int minute = time.getMinute(); // 30
    time = time.withSecond(6); // 20:30:06
    time = time.plusMinutes(3); // 20:33:06

    System.out.println(hour);
    System.out.println(minute);
    System.out.println(time);
  }
예제 #25
0
  public static void main(String[] args) {
    ZonedDateTime apollo11launch =
        ZonedDateTime.of(1969, 7, 16, 9, 32, 0, 0, ZoneId.of("America/New_York"));
    // 1969-07-16T09:32-04:00[America/New_York]
    System.out.println("apollo11launch: " + apollo11launch);

    Instant instant = apollo11launch.toInstant();
    System.out.println("instant: " + instant);

    ZonedDateTime zonedDateTime = instant.atZone(ZoneId.of("UTC"));
    System.out.println("zonedDateTime: " + zonedDateTime);

    ZonedDateTime skipped =
        ZonedDateTime.of(
            LocalDate.of(2013, 3, 31), LocalTime.of(2, 30), ZoneId.of("Europe/Berlin"));
    // Constructs March 31 3:30
    System.out.println("skipped: " + skipped);

    ZonedDateTime ambiguous =
        ZonedDateTime.of(
            LocalDate.of(2013, 10, 27), // End of daylight savings time
            LocalTime.of(2, 30),
            ZoneId.of("Europe/Berlin"));
    // 2013-10-27T02:30+02:00[Europe/Berlin]
    ZonedDateTime anHourLater = ambiguous.plusHours(1);
    // 2013-10-27T02:30+01:00[Europe/Berlin]
    System.out.println("ambiguous: " + ambiguous);
    System.out.println("anHourLater: " + anHourLater);

    ZonedDateTime meeting =
        ZonedDateTime.of(
            LocalDate.of(2013, 10, 31), LocalTime.of(14, 30), ZoneId.of("America/Los_Angeles"));
    System.out.println("meeting: " + meeting);
    ZonedDateTime nextMeeting = meeting.plus(Duration.ofDays(7));
    // Caution! Won’t work with daylight savings time
    System.out.println("nextMeeting: " + nextMeeting);
    nextMeeting = meeting.plus(Period.ofDays(7)); // OK
    System.out.println("nextMeeting: " + nextMeeting);
  }
  @Test
  public void checkUTCSchedule() {
    LocalTime startTime = LocalTime.of(8, 0);
    LocalTime endTime = LocalTime.of(17, 0);
    DayOfWeek startDay = DayOfWeek.MONDAY;
    DayOfWeek endDay = DayOfWeek.FRIDAY;
    ZoneId zoneId = ZoneId.of("UTC");

    SessionSchedule schedule =
        new DailyWeeklySessionSchedule(startDay, endDay, startTime, endTime, zoneId);

    // Sunday 1/17/2016 00:00
    checkSchedule("20160118-08:00:00", "20160118-17:00:00", "20160117-00:00:00", schedule);
    // Wednesday 1/20/2016 22:00
    checkSchedule("20160121-08:00:00", "20160121-17:00:00", "20160120-22:00:00", schedule);
    // Friday 1/22/2016 17:00
    checkSchedule("20160122-08:00:00", "20160122-17:00:00", "20160122-17:00:00", schedule);

    // Friday 1/22/2016 17:00:00.001
    checkSchedule("20160125-08:00:00", "20160125-17:00:00", "20160122-17:00:00.001", schedule);
    // Monday 1/25/2016 07:59:59.999
    checkSchedule("20160125-08:00:00", "20160125-17:00:00", "20160125-07:59:59.999", schedule);
  }
  @Test
  public void checkNewYorkSchedule() {
    // -5 hours from UTC, in 2016 year DST starts 13 March and ends 6 November
    LocalTime startTime = LocalTime.of(17, 0);
    LocalTime endTime = LocalTime.of(16, 0);
    DayOfWeek startDay = DayOfWeek.FRIDAY;
    DayOfWeek endDay = DayOfWeek.WEDNESDAY;
    ZoneId zoneId = ZoneId.of("America/New_York");

    SessionSchedule schedule =
        new DailyWeeklySessionSchedule(startDay, endDay, startTime, endTime, zoneId);

    // Friday 1/15/2016 17:00
    checkSchedule("20160115-22:00:00", "20160116-21:00:00", "20160115-22:00:00", schedule);
    // Sunday 1/17/2016 16:30
    checkSchedule("20160117-22:00:00", "20160118-21:00:00", "20160117-21:30:00", schedule);
    // Wednesday 1/20/2016 16:00
    checkSchedule("20160119-22:00:00", "20160120-21:00:00", "20160120-21:00:00", schedule);

    // Wednesday 1/20/2016 16:00:00.001
    checkSchedule("20160122-22:00:00", "20160123-21:00:00", "20160120-21:00:00.001", schedule);
    // Friday 1/22/2016 16:59:59.999
    checkSchedule("20160122-22:00:00", "20160123-21:00:00", "20160122-21:59:59.999", schedule);

    // DST start
    // Saturday 3/12/2016 18:00:00
    checkSchedule("20160312-22:00:00", "20160313-20:00:00", "20160312-23:00:00", schedule);
    // Sunday 3/13/2016 16:00:00.001
    checkSchedule("20160313-21:00:00", "20160314-20:00:00", "20160313-20:00:00.001", schedule);

    // DST end
    // Saturday 11/05/2016 16:30
    checkSchedule("20161105-21:00:00", "20161106-21:00:00", "20161105-20:30:00", schedule);
    // Sunday 11/06/2016 16:59
    checkSchedule("20161105-21:00:00", "20161106-21:00:00", "20161106-20:59:00", schedule);
  }
예제 #28
0
  private static void newAPI() {
    LocalDate soloFecha = LocalDate.now();
    LocalTime soloHora = LocalTime.now();
    LocalDateTime todo = LocalDateTime.now();

    ZonedDateTime zonedDateTime = ZonedDateTime.now();

    System.out.println("La fecha " + soloFecha);
    System.out.println("La hora " + soloHora);
    System.out.println("La fecha hora " + todo);
    System.out.println("La fecha hora y zona " + zonedDateTime);

    LocalDate myFecha = LocalDate.of(2015, Month.JULY, 2);
    LocalTime myHora = LocalTime.of(9, 21);

    System.out.println("Ayer fue: " + myFecha);
    System.out.println("La hora fue: " + myHora);
  }
예제 #29
0
public abstract class BaseJdbcTest {
  LocalDate date = LocalDate.of(2000, Month.JANUARY, 05);
  LocalTime time = LocalTime.of(12, 34, 56, 789054321);

  ResultSetWrapper getTimestampResultSetWrapper(Connection connection, LocalDateTime now)
      throws SQLException {
    DatabaseMetaData metaData = connection.getMetaData();
    connection
        .createStatement()
        .execute(
            "create table test1 (id int primary key, test1 timestamp, test2 date, test3 time)");
    PreparedStatement statement =
        connection.prepareStatement("insert into test1 values (?, ?, ?, ?)");
    statement.setInt(1, 1);
    PreparedStatementWrapper statementWrapper = new PreparedStatementWrapper(statement);
    statementWrapper.setLocalDateTime(2, now);
    statementWrapper.setLocalDate(3, date);
    statementWrapper.setLocalTime(4, time);
    assertEquals(1, statement.executeUpdate());
    ResultSet resultSet = connection.createStatement().executeQuery("select * from test1");
    assertTrue(resultSet.next());
    return new ResultSetWrapper(metaData, resultSet);
  }

  ResultSetWrapper getTimestampResultSetWrapperWithNulls(Connection connection)
      throws SQLException {
    DatabaseMetaData metaData = connection.getMetaData();
    connection
        .createStatement()
        .execute(
            "create table test1 (id int primary key, test1 timestamp, test2 date, test3 time)");
    PreparedStatement statement =
        connection.prepareStatement("insert into test1 values (?, ?, ?, ?)");
    statement.setInt(1, 1);
    PreparedStatementWrapper statementWrapper = new PreparedStatementWrapper(statement);
    statementWrapper.setLocalDateTime(2, null);
    statementWrapper.setLocalDate(3, null);
    statementWrapper.setLocalTime(4, null);
    assertEquals(1, statement.executeUpdate());
    ResultSet resultSet = connection.createStatement().executeQuery("select * from test1");
    assertTrue(resultSet.next());
    return new ResultSetWrapper(metaData, resultSet);
  }
}
  public static void main(String[] args) {
    LocalDateTime date1 = LocalDateTime.of(LocalDate.of(1999, 5, 15), LocalTime.of(10, 22));
    LocalDateTime date2 = LocalDateTime.of(LocalDate.of(2008, 2, 11), LocalTime.of(5, 33));
    System.out.println("date1: " + date1);
    System.out.println("date2: " + date2);

    System.out.println(ChronoUnit.YEARS.between(date1, date2));
    System.out.println(ChronoUnit.MONTHS.between(date1, date2));
    System.out.println(ChronoUnit.WEEKS.between(date1, date2));
    System.out.println(ChronoUnit.DAYS.between(date1, date2));
    System.out.println(ChronoUnit.HOURS.between(date1, date2));
    System.out.println(ChronoUnit.MINUTES.between(date1, date2));
    System.out.println(ChronoUnit.SECONDS.between(date1, date2));
  }