/** * Converts this object to a <code>LocalTime</code> with the * same time and chronology. * * @return a LocalTime with the same time and chronology * @since 1.3 */ public LocalTime toLocalTime() { return new LocalTime(getMillis(), getChronology()); }
/** * Output the time using the specified format pattern. * * @param pattern the pattern specification, null means use <code>toString</code> * @see org.joda.time.format.DateTimeFormat */ public String toString(String pattern) { if (pattern == null) { return toString(); } return DateTimeFormat.forPattern(pattern).print(this); }
/** * Converts this LocalTime to a full datetime using the default time zone * setting the time fields from this instance and the date fields from * the current date. * * @return this time as a datetime using today's date */ public DateTime toDateTimeToday() { return toDateTimeToday(null); }
/** * Returns a copy of this time with different local millis. * <p> * The returned object will be a new instance of the same type. * Only the millis will change, the chronology is kept. * The returned object will be either be a new instance or <code>this</code>. * * @param newMillis the new millis, from 1970-01-01T00:00:00 * @return a copy of this time with different millis */ LocalTime withLocalMillis(long newMillis) { return (newMillis == getLocalMillis() ? this : new LocalTime(newMillis, getChronology())); }
/** * Returns a copy of this datetime with the specified time, retaining the date fields. * <p> * If the new time is invalid due to the time-zone, the time will be adjusted. * <p> * This instance is immutable and unaffected by this method call. * * @param time the local time * @return a copy of this datetime with a different time * @throws IllegalArgumentException if the time-of-day is invalid for the date * @throws NullPointerException if the time is null */ public DateTime withTime(LocalTime time) { return withTime( time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond()); }
@Override public void write(Kryo kryo, Output output, LocalTime object) { final int time = object.getMillisOfDay(); output.writeInt(time, true); final Chronology chronology = object.getChronology(); if (chronology != null && chronology != ISOChronology.getInstanceUTC()) { throw new RuntimeException("Unsupported chronology: " + chronology); } }
@Override public TimeOfDay fromNonNullValue(Time value) { DateTime dateTime = new DateTime(value.getTime()); LocalTime localTime = dateTime.toLocalTime(); final TimeOfDay timeOfDay = new TimeOfDay(localTime.getHourOfDay(), localTime.getMinuteOfHour(), localTime.getSecondOfMinute(), localTime.getMillisOfSecond(), localTime.getChronology()); return timeOfDay; }
return 12.34; case "bound_date": return new LocalDate(2001, 8, 22).toDateMidnight(DateTimeZone.UTC).getMillis(); case "bound_time": return new LocalTime(3, 4, 5, 321).toDateTime(new DateTime(0, DateTimeZone.UTC)).getMillis(); case "bound_timestamp": return new DateTime(2001, 8, 22, 3, 4, 5, 321, DateTimeZone.UTC).getMillis(); case "bound_pattern": return utf8Slice("%el%");
return toDateTimeAtCurrentTime(zone); if (getChronology() != time.getChronology()) { throw new IllegalArgumentException("The chronology of the time does not match"); Chronology chrono = getChronology().withZone(zone); return new DateTime( getYear(), getMonthOfYear(), getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), chrono);
if (text.length() == 10 || text.length() == 8) { LocalDate localDate = parseLocalDate(text, format, formatter); localDateTime = localDate.toLocalDateTime(LocalTime.MIDNIGHT); } else { localDateTime = parseDateTime(text, formatter); localDate = localDateTime.toLocalTime(); } else { localDate = LocalTime.parse(text); return (T) new DateTime(millis, DateTimeZone.forTimeZone(timeZone));
public Object toDatabaseParam(LocalTime val) { return new Timestamp(val.toDateTimeToday().getMillis()); } }
@Override public Time getTime(int index) { org.joda.time.LocalTime time = new org.joda.time.LocalTime(ac.get(index), org.joda.time.DateTimeZone.UTC); // use "toDateTimeToday()" and "getMillis()" to get the local milliseconds from the Java epoch of 1970-01-01T00:00:00 return new TimePrintMillis(time.toDateTimeToday().getMillis()); }
@Override public Timestamp toNonNullValue(LocalTime value) { DateTime zonedValue = new LocalDateTime( 1970,1,1,value.getHourOfDay(), value.getMinuteOfHour(), value.getSecondOfMinute(), value.getMillisOfSecond(), value.getChronology() ).toDateTime(); final Timestamp timestamp = new Timestamp(zonedValue.getMillis()); return timestamp; } }
/** * Create a new {@link JodaTimeLocalTimeRangeRandomizer}. * @param min date * @param max date * @param seed initial seed */ public JodaTimeLocalTimeRangeRandomizer(final LocalTime min, final LocalTime max, final long seed) { super(min.toDateTimeToday().toDate(), max.toDateTimeToday().toDate(), seed); }
private void logWithTimestamp(final String debugInfo) { System.out.println(DateTime.now().toLocalTime().toString() + debugInfo); } }
Assert.assertThat(withJoda.getS(), is(withJsr310.getS())); Assert.assertThat(withJoda.getD().toString(), is(withJsr310.getD().toString())); Assert.assertThat(withJoda.getT().toString(), is(withJsr310.getT().toString())); Assert.assertThat(withJoda.getTs().toString(), is(withJsr310.getTs().toString())); Assert.assertThat(withJoda.getDec(), comparesEqualTo(withJsr310.getDec()));
@Test public void testToChar() throws Exception { String expectedResults[] = {(new LocalDate(2008, 2, 23)).toString("yyyy-MMM-dd"), (new LocalTime(12, 20, 30)).toString("HH mm ss"), (new LocalDateTime(2008, 2, 23, 12, 0, 0)).toString("yyyy MMM dd HH:mm:ss")}; testCommon(expectedResults, "/functions/date/to_char.json", "/test_simple_date.json"); }
/** * Constructs a LocalTime from the specified millis of day using the * specified chronology. * <p> * The millisOfDay value may exceed the number of millis in one day, * but additional days will be ignored. * This method uses the UTC time zone internally. * * @param millisOfDay the number of milliseconds into a day to convert * @param chrono the chronology, null means ISO chronology */ public static LocalTime fromMillisOfDay(long millisOfDay, Chronology chrono) { chrono = DateTimeUtils.getChronology(chrono).withUTC(); return new LocalTime(millisOfDay, chrono); }
@Override public long getLong(int field) { checkState(row != null, "No current row"); Column column = columns.get(field); if (column.getType().getBase() == ColumnType.Base.DATE) { return Days.daysBetween(new LocalDate(0), LocalDate.parse(row.get(column.getPosition()))).getDays(); } if (column.getType().getBase() == ColumnType.Base.TIME) { return LocalTime.parse(row.get(column.getPosition())).getMillisOfDay(); } if (column.getType().getBase() == ColumnType.Base.INTEGER) { return parseInt(row.get(column.getPosition())); } if (column.getType().getBase() == ColumnType.Base.DECIMAL) { DecimalParseResult decimalParseResult = Decimals.parse(row.get(column.getPosition())); return rescale((Long) decimalParseResult.getObject(), decimalParseResult.getType().getScale(), ((DecimalType) columnTypes.get(field)).getScale()); } return parseLong(row.get(column.getPosition())); }