/** * Returns a copy of this datetime with the specified date, retaining the time fields. * <p> * If the time is invalid on the new date due to the time-zone, the time will be adjusted. * <p> * This instance is immutable and unaffected by this method call. * * @param date the local date * @return a copy of this datetime with a different date * @throws IllegalArgumentException if the time-of-day is invalid for the date * @throws NullPointerException if the date is null */ public DateTime withDate(LocalDate date) { return withDate( date.getYear(), date.getMonthOfYear(), date.getDayOfMonth()); }
/** * Returns a copy of this datetime with the specified date, retaining the time fields. * <p> * If the time is invalid on the new date due to the time-zone, the time will be adjusted. * <p> * This instance is immutable and unaffected by this method call. * * @param date the local date * @return a copy of this datetime with a different date * @throws IllegalArgumentException if the time-of-day is invalid for the date * @throws NullPointerException if the date is null */ public DateTime withDate(LocalDate date) { return withDate( date.getYear(), date.getMonthOfYear(), date.getDayOfMonth()); }
DateTime date = tryParseDateTime(s, stringToParse); if (date != null) { resultDateTime = resultDateTime.withDate(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth()); break; DateTime date = tryParseDateTime(monthDayOptionalYearFormat, stringToParse); if (date != null) resultDateTime = resultDateTime.withDate(resultDateTime.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
@Test public void testComplexFormats() { testFormat("12:24 yesterday", nowDateTime().minusDays(1).withHourOfDay(12).withMinuteOfHour(24)); testFormat("12:24 tomorrow", nowDateTime().plusDays(1).withHourOfDay(12).withMinuteOfHour(24)); testFormat("12:24 today", nowDateTime().withHourOfDay(12).withMinuteOfHour(24)); testFormat("noon 12/30/2014", nowDateTime().withDate(2014, 12, 30).withHourOfDay(12).withMinuteOfHour(0)); int currentYear = referenceDateTime().getYear(); testFormat("15:45 12/30/14", new DateTime(2014, 12, 30, 15, 45, 0, 0)); testFormat("teatime 12/30/2014", new DateTime(2014, 12, 30, 16, 0, 0, 0)); testFormat("midnight Jul 30", new DateTime(currentYear, 07, 30, 0, 0, 0, 0)); testFormat("Jul 30, 2013", new DateTime(2013, 07, 30, 0, 0, 0, 0)); testFormat("Jul 30", new DateTime(currentYear, 07, 30, 0, 0, 0, 0)); testFormat("20141230", new DateTime(2014, 12, 30, 0, 0, 0, 0)); }
public JpaBatchJobExecutionStatusCounts(String status, Integer year, Integer month, Integer day, Long count) { this.status = status; this.count = count; this.date = new DateTime().withDate(year, month, day); }
DateTime initial = new DateTime( 1970, 1, 1, 22, 30, 0 ); DateTime dayUpdated = initial.withDate( 1980, 2, 3 ); DateTime timeUpdated = initial.withTime( 15, 20, 0, 0 ); // At this point, initial still contains 1970-1-1, 22:30 // dayUpdated is 1980-2-3 22:30 // timeUpdated is 1970-1-1 15:20
public JpaBatchJobExecutionStatusCounts(String status, String feedName, Integer year, Integer month, Integer day, Long count) { this.status = status; this.count = count; this.feedName = feedName; this.date = new DateTime().withDate(year, month, day).withMillisOfDay(0); }
/** * Create a Time object set to the current time. */ public Time() { final DateTime dateTime = Clock.getTimeAsDateTime(); time = dateTime.withDate(1970, 1, 1); // Epoch is 1970-01-01 }
/** * Create a Time object set to the current time. */ public Time() { final DateTime dateTime = Clock.getTimeAsDateTime(); time = dateTime.withDate(1970, 1, 1); // Epoch is 1970-01-01 }
@JsonIgnore public DateTime getMaxTime() { return new DateTime() .withZone(DateTimeZone.UTC) .withDate(2037, 12, 31) .withTime(0, 0, 0, 0); }
public static DateTime getMaxTime() { return new DateTime() .withZone(DateTimeZone.UTC) .withDate(2037, 12, 31) .withTime(0, 0, 0, 0); }
@Test public void topicShouldShowCurrentTopicSystemMessageIfNoArgumentsAndTopicSet() throws CommandException { final long date = new DateTime().withDate(2010, 3, 4).withTime(20, 45, 13, 0).getMillis(); topic.changeTopic(new Topic("What a nice day", "Niles", date)); when(dateTools.dateToString(any(Date.class), anyString())).thenCallRealMethod(); parser.parse("/topic"); verify(messageController).showSystemMessage( "Topic is: What a nice day (set by Niles at 20:45:13, 04. Mar. 10)"); verify(parser, never()).fixTopic(anyString()); }
@Test public void dateToStringShouldConvertSpecifiedDateToStringWithCorrectFormat() { final Date date = new DateTime().withDate(2014, 5, 13).withTime(23, 52, 28, 0).toDate(); final String dateAsString = dateTools.dateToString(date, "dd.MM.yyyy HH:mm:ss"); assertEquals("13.05.2014 23:52:28", dateAsString); }
@Test public void topicChangedShouldUpdateTopicAndShowTopicIsMessageWhenNotDoneWithLogonYet() { final Topic topic = new Topic(); when(controller.getTopic()).thenReturn(topic); when(chatState.isLogonCompleted()).thenReturn(false); final long time = new DateTime().withDate(2013, 8, 22).withTime(13, 45, 5, 0).toDate().getTime(); responder.topicChanged(300, "See ya!", "Harry", time); verify(messageController).showSystemMessage("Topic is: See ya! (set by Harry at 13:45:05, 22. Aug. 13)"); verify(userInterface).showTopic(); verifyTopic(topic, "See ya!", "Harry", time); }
@Test(expected = RuntimeException.class) public void testForCastTypeNotSupported() { operands.add(BeamSqlPrimitive.of(SqlTypeName.TIME, DateTime.now())); Assert.assertEquals( new DateTime().withDate(2017, 05, 22).withTime(0, 0, 0, 0), new BeamSqlCastExpression(operands, SqlTypeName.TIMESTAMP) .evaluate(row, null, BeamSqlExpressionEnvironments.empty()) .getValue()); } }
@Test public void testyyMMddDateFormat() { // test for yy.MM.dd format operands.add(BeamSqlPrimitive.of(SqlTypeName.VARCHAR, "17.05.21")); Assert.assertEquals( new DateTime().withDate(2017, 05, 21).withTimeAtStartOfDay(), new BeamSqlCastExpression(operands, SqlTypeName.DATE) .evaluate(row, null, BeamSqlExpressionEnvironments.empty()) .getValue()); }
@Test public void testDateTimeFormatWithMillis() { operands.add(BeamSqlPrimitive.of(SqlTypeName.VARCHAR, "2017-05-21 23:59:59.989")); Assert.assertEquals( new DateTime().withDate(2017, 05, 22).withTime(0, 0, 0, 0), new BeamSqlCastExpression(operands, SqlTypeName.TIMESTAMP) .evaluate(row, null, BeamSqlExpressionEnvironments.empty()) .getValue()); }
@Test public void testForIntegerToDateCast() { // test for yyyyMMdd format operands.add(BeamSqlPrimitive.of(SqlTypeName.INTEGER, 20170521)); Assert.assertEquals( new DateTime().withDate(2017, 05, 21).withTimeAtStartOfDay(), new BeamSqlCastExpression(operands, SqlTypeName.DATE) .evaluate(row, null, BeamSqlExpressionEnvironments.empty()) .getValue()); }
@Test public void testDateTimeFormat() { operands.add(BeamSqlPrimitive.of(SqlTypeName.VARCHAR, "2017-05-21 23:59:59")); Assert.assertEquals( new DateTime().withDate(2017, 05, 21).withTime(23, 59, 59, 0), new BeamSqlCastExpression(operands, SqlTypeName.TIMESTAMP) .evaluate(row, null, BeamSqlExpressionEnvironments.empty()) .getValue()); }