@SuppressWarnings("unchecked") @Override public void readExternal(ObjectInput arg0) throws IOException, ClassNotFoundException { createdDate = (LocalDate) arg0.readObject(); createdTime = (LocalTime) arg0.readObject(); user = (User) arg0.readObject(); serveAtDate = (LocalDate) arg0.readObject(); serveAtTime = (LocalTime) arg0.readObject(); active = (boolean) arg0.readObject(); number = (String) arg0.readObject(); orderedMeals = (ArrayList<MealAndQuantity>) arg0.readObject(); sspCreatedDate = new SimpleStringProperty(createdDate.toString()); sspCreatedTime = new SimpleStringProperty(createdTime.toString()); sspOrderedMeals = new SimpleStringProperty(); sspUserName = new SimpleStringProperty(user.getUserName().get()); sspNumber = new SimpleStringProperty(number.toString()); sspServeAtDate = new SimpleStringProperty(serveAtDate.toString()); sspServeAtTime = new SimpleStringProperty(serveAtTime.toString()); sspPrice = new SimpleStringProperty(); sspCreatedAtCompact = new SimpleStringProperty(createdDate.toString() + " " + createdTime.toString()); sspServeAtCompact = new SimpleStringProperty(serveAtDate.toString() + " " + serveAtTime.toString()); }
// ----------------------------------------------------------------------- public void testWithField_DateTimeFieldType_int_1() { LocalTime test = new LocalTime(10, 20, 30, 40); LocalTime result = test.withField(DateTimeFieldType.hourOfDay(), 15); assertEquals(new LocalTime(10, 20, 30, 40), test); assertEquals(new LocalTime(15, 20, 30, 40), result); }
// ----------------------------------------------------------------------- public void testToString_String_Locale() { LocalTime test = new LocalTime(10, 20, 30, 40); assertEquals("10 20", test.toString("H m", Locale.ENGLISH)); assertEquals("10:20:30.040", test.toString(null, Locale.ENGLISH)); assertEquals("10 20", test.toString("H m", null)); assertEquals("10:20:30.040", test.toString(null, null)); }
public Order( User user, LocalDate createdAtDate, LocalTime createdAtTime, LocalDate serveAtDate, LocalTime serveAtTime, String orderNumber, String desc) throws NullPointerException { this.createdDate = createdAtDate; this.createdTime = createdAtTime; this.user = user; createdTime = LocalTime.now(); this.serveAtDate = serveAtDate; this.serveAtTime = serveAtTime; this.description = desc; orderedMeals = new ArrayList<>(); number = orderNumber; sspCreatedDate = new SimpleStringProperty(createdDate.toString()); sspCreatedTime = new SimpleStringProperty(createdTime.toString()); sspOrderedMeals = new SimpleStringProperty(); sspUserName = new SimpleStringProperty(this.user.getUserName().get()); sspNumber = new SimpleStringProperty(number.toString()); sspServeAtDate = new SimpleStringProperty(serveAtDate.toString()); sspServeAtTime = new SimpleStringProperty(serveAtTime.toString()); sspPrice = new SimpleStringProperty(); sspDescription = new SimpleStringProperty(description); sspCreatedAtCompact = new SimpleStringProperty(createdDate.toString() + " " + createdTime.toString()); sspServeAtCompact = new SimpleStringProperty(serveAtDate.toString() + " " + serveAtTime.toString()); }
public void testWithFieldAdded_DurationFieldType_int_6() { LocalTime test = new LocalTime(10, 20, 30, 40); LocalTime result = test.withFieldAdded(DurationFieldType.hours(), 16); assertEquals(new LocalTime(10, 20, 30, 40), test); assertEquals(new LocalTime(2, 20, 30, 40), result); }
public void testToDateTime_nullRI() { LocalTime base = new LocalTime(1, 2, 3, 4); DateTimeUtils.setCurrentMillisFixed(TEST_TIME2); DateTime test = base.toDateTime((ReadableInstant) null); check(base, 1, 2, 3, 4); assertEquals("1970-01-02T01:02:03.004+01:00", test.toString()); }
public void testWithField_DateTimeFieldType_int_3() { LocalTime test = new LocalTime(10, 20, 30, 40); try { test.withField(DateTimeFieldType.dayOfMonth(), 6); fail(); } catch (IllegalArgumentException ex) { } }
public void testWithFieldAdded_DurationFieldType_int_5() { LocalTime test = new LocalTime(10, 20, 30, 40); try { test.withFieldAdded(DurationFieldType.days(), 6); fail(); } catch (IllegalArgumentException ex) { } }
// ----------------------------------------------------------------------- public void testMinus_RP() { LocalTime test = new LocalTime(10, 20, 30, 40, BUDDHIST_LONDON); LocalTime result = test.minus(new Period(1, 1, 1, 1, 1, 1, 1, 1)); LocalTime expected = new LocalTime(9, 19, 29, 39, BUDDHIST_LONDON); assertEquals(expected, result); result = test.minus((ReadablePeriod) null); assertSame(test, result); }
public void testGetFields() { LocalTime test = new LocalTime(10, 20, 30, 40, COPTIC_UTC); DateTimeField[] fields = test.getFields(); assertSame(COPTIC_UTC.hourOfDay(), fields[0]); assertSame(COPTIC_UTC.minuteOfHour(), fields[1]); assertSame(COPTIC_UTC.secondOfMinute(), fields[2]); assertSame(COPTIC_UTC.millisOfSecond(), fields[3]); assertNotSame(test.getFields(), test.getFields()); }
public void testGetValues() { LocalTime test = new LocalTime(10, 20, 30, 40, COPTIC_UTC); int[] values = test.getValues(); assertEquals(10, values[0]); assertEquals(20, values[1]); assertEquals(30, values[2]); assertEquals(40, values[3]); assertNotSame(test.getValues(), test.getValues()); }
public void testPlusSeconds_int() { LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON); LocalTime result = test.plusSeconds(1); LocalTime expected = new LocalTime(1, 2, 4, 4, BUDDHIST_LONDON); assertEquals(expected, result); result = test.plusSeconds(0); assertSame(test, result); }
public void testMinusMillis_int() { LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON); LocalTime result = test.minusMillis(1); LocalTime expected = new LocalTime(1, 2, 3, 3, BUDDHIST_LONDON); assertEquals(expected, result); result = test.minusMillis(0); assertSame(test, result); }
// ----------------------------------------------------------------------- public void testPlus_RP() { LocalTime test = new LocalTime(10, 20, 30, 40, BUDDHIST_LONDON); LocalTime result = test.plus(new Period(1, 2, 3, 4, 5, 6, 7, 8)); LocalTime expected = new LocalTime(15, 26, 37, 48, BUDDHIST_LONDON); assertEquals(expected, result); result = test.plus((ReadablePeriod) null); assertSame(test, result); }
// ----------------------------------------------------------------------- public void testToDateTime_RI() { LocalTime base = new LocalTime(10, 20, 30, 40, COPTIC_PARIS); DateTime dt = new DateTime(0L); // LONDON zone assertEquals("1970-01-01T01:00:00.000+01:00", dt.toString()); DateTime test = base.toDateTime(dt); check(base, 10, 20, 30, 40); assertEquals("1970-01-01T01:00:00.000+01:00", dt.toString()); assertEquals("1970-01-01T10:20:30.040+01:00", test.toString()); }
public void testToDateTimeToday_nullZone() { LocalTime base = new LocalTime(10, 20, 30, 40, COPTIC_PARIS); // PARIS irrelevant DateTime dt = new DateTime(2004, 6, 9, 6, 7, 8, 9); DateTimeUtils.setCurrentMillisFixed(dt.getMillis()); DateTime test = base.toDateTimeToday((DateTimeZone) null); check(base, 10, 20, 30, 40); DateTime expected = new DateTime(dt.getMillis(), COPTIC_LONDON); expected = expected.hourOfDay().setCopy(10); expected = expected.minuteOfHour().setCopy(20); expected = expected.secondOfMinute().setCopy(30); expected = expected.millisOfSecond().setCopy(40); assertEquals(expected, test); }
public void testGetValue_int() { LocalTime test = new LocalTime(10, 20, 30, 40, COPTIC_PARIS); assertEquals(10, test.getValue(0)); assertEquals(20, test.getValue(1)); assertEquals(30, test.getValue(2)); assertEquals(40, test.getValue(3)); try { test.getValue(-1); } catch (IndexOutOfBoundsException ex) { } try { test.getValue(5); } catch (IndexOutOfBoundsException ex) { } }
public void testWithFieldAdded_DurationFieldType_int_8() { LocalTime test = new LocalTime(0, 0, 0, 0); LocalTime result = test.withFieldAdded(DurationFieldType.millis(), -1); assertEquals(new LocalTime(23, 59, 59, 999), result); test = new LocalTime(0, 0, 0, 0); result = test.withFieldAdded(DurationFieldType.seconds(), -1); assertEquals(new LocalTime(23, 59, 59, 0), result); test = new LocalTime(0, 0, 0, 0); result = test.withFieldAdded(DurationFieldType.minutes(), -1); assertEquals(new LocalTime(23, 59, 0, 0), result); test = new LocalTime(0, 0, 0, 0); result = test.withFieldAdded(DurationFieldType.hours(), -1); assertEquals(new LocalTime(23, 0, 0, 0), result); }
public static ZonedDateTime getNextSchedule() { ZonedDateTime next_schedule; // Determine type of schedule if (ConfigHandler.backupInterval > 0) // Interval { next_schedule = ZonedDateTime.ofInstant( Instant.ofEpochMilli( System.currentTimeMillis() + (ConfigHandler.backupInterval * 60 * 1000)), ZoneId.systemDefault()); } else // Schedule { if (ConfigHandler.backupSchedule.length == 0) { return null; } LocalTime now = LocalTime.now(); LocalTime next_time = null; LocalDate day = LocalDate.now(); TreeSet<LocalTime> times = new TreeSet<>(); for (String s : ConfigHandler.backupSchedule) { times.add(LocalTime.parse(s, DateTimeFormatter.ofPattern("H:mm"))); } for (LocalTime t : times) // try to find next scheduled time for today { if (t.compareTo(now) == 1) { next_time = t; break; } } if (next_time == null) // if we couldn't find one for today take the first schedule time for tomorrow { day = day.plusDays(1); next_time = times.first(); } next_schedule = ZonedDateTime.of(day, next_time, ZoneId.systemDefault()); } return next_schedule; }
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); }
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(); }
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); }
// ----------------------------------------------------------------------- public void testGetters() { LocalTime test = new LocalTime(10, 20, 30, 40); assertEquals(10, test.getHourOfDay()); assertEquals(20, test.getMinuteOfHour()); assertEquals(30, test.getSecondOfMinute()); assertEquals(40, test.getMillisOfSecond()); assertEquals(TEST_TIME_NOW, test.getMillisOfDay()); }
public Order(User user, LocalDate serveAtDate, LocalTime serveAtTime) { createdDate = LocalDate.now(); createdTime = LocalTime.now(); this.user = user; this.serveAtDate = serveAtDate; this.serveAtTime = serveAtTime; orderedMeals = new ArrayList<>(); number = new String(createdDate + "-" + createdTime + "-" + (++user.orderCount)); sspCreatedDate = new SimpleStringProperty(createdDate.toString()); sspCreatedTime = new SimpleStringProperty(createdTime.toString()); sspOrderedMeals = new SimpleStringProperty(); sspUserName = new SimpleStringProperty(user.getUserName().get()); sspNumber = new SimpleStringProperty(number.toString()); sspServeAtDate = new SimpleStringProperty(serveAtDate.toString()); sspServeAtTime = new SimpleStringProperty(serveAtTime.toString()); sspPrice = new SimpleStringProperty(); sspCreatedAtCompact = new SimpleStringProperty(createdDate.toString() + " " + createdTime.toString()); sspServeAtCompact = new SimpleStringProperty(serveAtDate.toString() + " " + serveAtTime.toString()); }
// ----------------------------------------------------------------------- public void testWithers() { LocalTime test = new LocalTime(10, 20, 30, 40); check(test.withHourOfDay(6), 6, 20, 30, 40); check(test.withMinuteOfHour(6), 10, 6, 30, 40); check(test.withSecondOfMinute(6), 10, 20, 6, 40); check(test.withMillisOfSecond(6), 10, 20, 30, 6); check(test.withMillisOfDay(61234), 0, 1, 1, 234); try { test.withHourOfDay(-1); fail(); } catch (IllegalArgumentException ex) { } try { test.withHourOfDay(24); fail(); } catch (IllegalArgumentException ex) { } }
public void testIsSupported_DurationFieldType() { LocalTime test = new LocalTime(10, 20, 30, 40); assertEquals(true, test.isSupported(DurationFieldType.hours())); assertEquals(true, test.isSupported(DurationFieldType.minutes())); assertEquals(true, test.isSupported(DurationFieldType.seconds())); assertEquals(true, test.isSupported(DurationFieldType.millis())); assertEquals(true, test.isSupported(DurationFieldType.halfdays())); assertEquals(false, test.isSupported(DurationFieldType.days())); assertEquals(false, test.isSupported((DurationFieldType) null)); }
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); }
// ----------------------------------------------------------------------- public void testSerialization() throws Exception { LocalTime test = new LocalTime(10, 20, 30, 40, COPTIC_PARIS); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(test); oos.close(); byte[] bytes = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bais); LocalTime result = (LocalTime) ois.readObject(); ois.close(); assertEquals(test, result); assertTrue(Arrays.equals(test.getValues(), result.getValues())); assertTrue(Arrays.equals(test.getFields(), result.getFields())); assertEquals(test.getChronology(), result.getChronology()); }
public void testGetFieldType_int() { LocalTime test = new LocalTime(10, 20, 30, 40); assertSame(DateTimeFieldType.hourOfDay(), test.getFieldType(0)); assertSame(DateTimeFieldType.minuteOfHour(), test.getFieldType(1)); assertSame(DateTimeFieldType.secondOfMinute(), test.getFieldType(2)); assertSame(DateTimeFieldType.millisOfSecond(), test.getFieldType(3)); try { test.getFieldType(-1); } catch (IndexOutOfBoundsException ex) { } try { test.getFieldType(5); } catch (IndexOutOfBoundsException ex) { } }
public void testGetField_int() { LocalTime test = new LocalTime(10, 20, 30, 40, COPTIC_UTC); assertSame(COPTIC_UTC.hourOfDay(), test.getField(0)); assertSame(COPTIC_UTC.minuteOfHour(), test.getField(1)); assertSame(COPTIC_UTC.secondOfMinute(), test.getField(2)); assertSame(COPTIC_UTC.millisOfSecond(), test.getField(3)); try { test.getField(-1); } catch (IndexOutOfBoundsException ex) { } try { test.getField(5); } catch (IndexOutOfBoundsException ex) { } }