Refine search
/** * Perform a sanity check to make sure that the year is reasonably current, to guard against * issues in third party libraries. */ public static void verifySystemTimeIsReasonable() { int currentYear = DateTime.now().year().get(); if (currentYear < 2019) { failRequirement("Presto requires the system time to be current (found year %s)", currentYear); } }
return setCopy(getMaximumValue()); } catch (RuntimeException ex) { if (IllegalInstantException.isIllegalInstant(ex)) { long beforeGap = getChronology().getZone().previousTransition(getMillis() + DateTimeConstants.MILLIS_PER_DAY); return new DateTime(beforeGap, getChronology());
@Test public void testTimestampsInResponseLosAngelesTimeZone() throws Exception { final ResultSet resultSet = clientLosAngeles.createStatement().executeQuery( "SELECT __time, CAST(__time AS DATE) AS t2 FROM druid.foo LIMIT 1" ); final DateTimeZone timeZone = DateTimes.inferTzFromString("America/Los_Angeles"); final DateTime localDateTime = new DateTime("2000-01-01T00Z", timeZone); final List<Map<String, Object>> resultRows = getRows(resultSet); Assert.assertEquals( ImmutableList.of( ImmutableMap.of( "__time", new Timestamp(Calcites.jodaToCalciteTimestamp(localDateTime, timeZone)), "t2", new Date(Calcites.jodaToCalciteTimestamp(localDateTime.dayOfMonth().roundFloorCopy(), timeZone)) ) ), resultRows ); }
/** * 获得当前月的最后一天 * @param date 日期 * @return 当前月的最后一天 */ public static Date endDateOfMonth(Date date) { DateTime dateTime = new DateTime(date); return dateTime.dayOfMonth().withMaximumValue().toDate(); }
/** * 获得当前周最后一天 周日 * @param date 日期 * @return 当前周最后一天 */ public static Date endDateOfWeek(Date date){ DateTime dateTime = new DateTime(date); return dateTime.dayOfWeek().withMaximumValue().toDate(); } }
/** * 获取指定日期当天的结束时间 * @param date 日期 * @return 时间 */ public static Date endOfDay(Date date) { return new DateTime(date).millisOfDay().withMaximumValue().toDate(); }
public static TimePeriod createMonthViewDates(int month, int year) { Date start = new DateTime().dayOfMonth() .setCopy(1) .monthOfYear() .setCopy(month) .year() .setCopy(year) .toDate(); Date end = new DateTime(start).plusMonths(1).minusDays(1).toDate(); return new TimePeriod(start, end); }
public static TimePeriod createMonthViewDates() { Date start = new DateTime().dayOfMonth().setCopy(1).toDate(); Date end = new DateTime(start).plusMonths(1).minusDays(1).toDate(); return new TimePeriod(start, end); }
/** * 获取当前周的周一和下周一 * * @return 日期数组(索引0为周一,索引1为下周一) */ public static Date[] getMondayAndNextMonday() { DateTime dateTime = getDateOnly(new DateTime()); DateTime monday = dateTime.dayOfWeek().withMinimumValue(); DateTime nextMonday = monday.plusDays(7); return new Date[]{monday.toDate(), nextMonday.toDate()}; }
/** * * @param date * must have Date portion equal to Epoch * @param calendar */ public Time(final java.util.Date date, final DateTimeZone dateTimeZone) { final DateTime DateTime = new DateTime(date.getTime(), dateTimeZone); this.time = DateTime.secondOfMinute().setCopy(0); }
@Override public int weeksInYear( int year ) { DateTime dateTime = new DateTime( year, 1, 1, 0, 0, ISOChronology.getInstance( DateTimeZone.getDefault() ) ); return dateTime.weekOfWeekyear().getMaximumValue(); }
/** * Return the last day of datetime * * @param date * @return DateTime */ public static DateTime getLastDayOfTheMonth(DateTime date) { if (null == date) { return null; } date = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), 23, 59, 59, 999); return date.dayOfMonth().withMaximumValue(); }
String expYear = parsedDate[1]; try { DateTime expirationDate = new DateTime(Integer.parseInt("20" + expYear), Integer.parseInt(expMonth), 1, 0, 0); expirationDate = expirationDate.dayOfMonth().withMaximumValue(); validDate = expirationDate.isAfterNow(); validDateFormat = true; } catch (Exception e) {
/** * Returns date minus 6 hours to indicate the high latency pipeline timestamp */ public static DateTime currentHighLatencyTime(DateTimeZone zone) { return new DateTime(zone).minusHours(DELAY_HOURS).minuteOfHour() .withMinimumValue().secondOfMinute().withMinimumValue().millisOfSecond() .withMinimumValue(); }
@Override public String getFormattedDateString(long timeMillis) { // For better handling of days at the end of the year. DateTime dt = new DateTime(timeMillis); if (dt.monthOfYear().get() == 12 && dt.weekOfWeekyear().get() < 3) { return dt.getYearOfCentury() + "53"; } return Integer.toString(dt.weekyear().get() % 1000) + String.format("%02d", dt.weekOfWeekyear().get()); }
@Override public Object provide(Object source, Object currentValue) { IFormation formation = (IFormation) source; int firstYear = formation.getFirstYear(); int currentYear = new DateTime().year().get(); Set<String> years = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); do { years.add(String.valueOf(firstYear)); } while (++firstYear <= currentYear); return years; }
@Override public List<BonusPointRecord> getByUserIdAndCurrentMonth(String userId) { Date currentMonth = DateTime.now().dayOfMonth().withMinimumValue().hourOfDay().withMinimumValue().millisOfDay().withMinimumValue().toDate(); BonusPointRecord bonusPointRecord = new BonusPointRecord(); bonusPointRecord.setAccountId(userId); bonusPointRecord.setCreateDate(currentMonth); return bonusPointRecordDao.loadByUSerIdAndCurrentMonth(bonusPointRecord); }
case MILLISECONDS: _dateTimeTruncate = (dateTime) -> _outputDateTimeFormatter .print(dateTime.withMillisOfSecond((dateTime.getMillisOfSecond() / sz) * sz)); break; case SECONDS: _dateTimeTruncate = (dateTime) -> _outputDateTimeFormatter.print( dateTime.withSecondOfMinute((dateTime.getSecondOfMinute() / sz) * sz).secondOfMinute().roundFloorCopy()); break; case MINUTES: _dateTimeTruncate = (dateTime) -> _outputDateTimeFormatter .print(dateTime.withMinuteOfHour((dateTime.getMinuteOfHour() / sz) * sz).minuteOfHour().roundFloorCopy()); break; case HOURS: _dateTimeTruncate = (dateTime) -> _outputDateTimeFormatter .print(dateTime.withHourOfDay((dateTime.getHourOfDay() / sz) * sz).hourOfDay().roundFloorCopy()); break; case DAYS: _dateTimeTruncate = (dateTime) -> _outputDateTimeFormatter .print(dateTime.withDayOfMonth((dateTime.getDayOfMonth() / sz) * sz).dayOfMonth().roundFloorCopy()); break; default:
private long getMilisFromDateClearDay(String createdAt) { DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"); DateTime dt = formatter.parseDateTime(createdAt); return dt.minuteOfDay().roundFloorCopy().getMillis(); }
@Override public long roundDateTime(DateTime datetime) { return datetime.monthOfYear().roundFloorCopy().getMillis(); }