Refine search
@Description("current date") @ScalarFunction @SqlType(StandardTypes.DATE) public static long currentDate(ConnectorSession session) { ISOChronology chronology = getChronology(session.getTimeZoneKey()); // It is ok for this method to use the Object interfaces because it is constant folded during // plan optimization LocalDate currentDate = new DateTime(session.getStartTime(), chronology).toLocalDate(); return Days.daysBetween(new LocalDate(1970, 1, 1), currentDate).getDays(); }
return MIN_VALUE; default: return new Days(days);
/** * Returns a new instance with the specified number of days added. * <p> * This instance is immutable and unaffected by this method call. * * @param days the amount of days to add, may be negative, null means zero * @return the new period plus the specified number of days * @throws ArithmeticException if the result overflows an int */ public Days plus(Days days) { if (days == null) { return this; } return plus(days.getValue()); }
/** * Returns a new instance with the days value negated. * * @return the new period with a negated value * @throws ArithmeticException if the result overflows an int */ public Days negated() { return Days.days(FieldUtils.safeNegate(getValue())); }
@Test public void testDateDiffDate() { DateTime baseDateTime = new DateTime(1960, 5, 3, 0, 0, 0, 0, DateTimeZone.UTC); String baseDateTimeLiteral = "DATE '1960-05-03'"; assertFunction("date_diff('day', " + baseDateTimeLiteral + ", " + DATE_LITERAL + ")", BIGINT, (long) daysBetween(baseDateTime, DATE).getDays()); assertFunction("date_diff('week', " + baseDateTimeLiteral + ", " + DATE_LITERAL + ")", BIGINT, (long) weeksBetween(baseDateTime, DATE).getWeeks()); assertFunction("date_diff('month', " + baseDateTimeLiteral + ", " + DATE_LITERAL + ")", BIGINT, (long) monthsBetween(baseDateTime, DATE).getMonths()); assertFunction("date_diff('quarter', " + baseDateTimeLiteral + ", " + DATE_LITERAL + ")", BIGINT, (long) monthsBetween(baseDateTime, DATE).getMonths() / 3); assertFunction("date_diff('year', " + baseDateTimeLiteral + ", " + DATE_LITERAL + ")", BIGINT, (long) yearsBetween(baseDateTime, DATE).getYears()); }
DateTime now = DateTime.now(time.getZone()).withMillisOfSecond(0); DateTime timeDt = new DateTime(time).withMillisOfSecond(0); boolean past = !now.isBefore(timeDt); Interval interval = past ? new Interval(timeDt, now) : new Interval(now, timeDt); else if (Hours.hoursIn(interval).isLessThan(Hours.ONE)) { count = Minutes.minutesIn(interval).getMinutes(); if (past) { else if (Days.daysIn(interval).isLessThan(Days.ONE)) { count = Hours.hoursIn(interval).getHours(); if (past) { if (abbrevRelative) { else if (Weeks.weeksIn(interval).isLessThan(Weeks.ONE)) { count = Days.daysIn(interval).getDays(); if (past) { if (abbrevRelative) {
private static void dateDiff() { System.out.println("Calculate difference between two dates"); System.out.println("================================================================="); DateTime startDate = new DateTime(2000, 1, 19, 0, 0, 0, 0); DateTime endDate = new DateTime(); Days d = Days.daysBetween(startDate, endDate); int days = d.getDays(); System.out.println(" Difference between " + endDate); System.out.println(" and " + startDate + " is " + days + " days."); }
MutableDateTime epoch = new MutableDateTime(); epoch.setDate(0); //Set to Epoch time DateTime now = new DateTime(); Days days = Days.daysBetween(epoch, now); Weeks weeks = Weeks.weeksBetween(epoch, now); Months months = Months.monthsBetween(epoch, now); System.out.println("Days Since Epoch: " + days.getDays()); System.out.println("Weeks Since Epoch: " + weeks.getWeeks()); System.out.println("Months Since Epoch: " + months.getMonths());
DateTime nowTime = new DateTime(); DateTime msgTime = new DateTime(msgTimeMillis); int days = Math.abs(Days.daysBetween(msgTime, nowTime).getDays()); } else if (days <= 7) { switch (msgTime.getDayOfWeek()) { case DateTimeConstants.SUNDAY: return "周日 " + getTime(msgTime);
final DateTime baseTime = new DateTime("2012-11-04T00:00:00", tz); assertSameInterval( Lists.newArrayList( new DateTime("2012-11-04T00:00:00.000-07:00", tz), new DateTime("2012-11-05T00:00:00.000-08:00", tz), new DateTime("2012-11-06T00:00:00.000-08:00", tz) ), new PeriodGranularity(new Period("P1D"), null, tz) .getIterable(new Interval(baseTime, baseTime.plus(Days.days(3)))) ); ), new PeriodGranularity(new Period("PT1H"), null, tz) .getIterable(new Interval(baseTime, baseTime.plus(Hours.hours(5)))) );
@Override protected boolean isToFire() { int days = Days.daysBetween(calculateStartDate().toDateMidnight(), new LocalDate().toDateMidnight()).getDays(); return days >= INTERVAL; }
static int computeOffsetFromUtc(final DateTime effectiveDateTime, final DateTimeZone accountTimeZone) { final LocalDate localDateInAccountTimeZone = new LocalDate(effectiveDateTime, accountTimeZone); final LocalDate localDateInUTC = new LocalDate(effectiveDateTime, DateTimeZone.UTC); return Days.daysBetween(localDateInUTC, localDateInAccountTimeZone).getDays(); }
/** * Calcite expects "DATE" types to be number of days from the epoch to the UTC date matching the local time fields. * * @param dateTime joda timestamp * @param timeZone session time zone * * @return Calcite style date */ public static int jodaToCalciteDate(final DateTime dateTime, final DateTimeZone timeZone) { final DateTime date = dateTime.withZone(timeZone).dayOfMonth().roundFloorCopy(); return Days.daysBetween(DateTimes.EPOCH, date.withZoneRetainFields(DateTimeZone.UTC)).getDays(); }
@Override public Integer toInt(LocalDate date, Schema schema, LogicalType type) { return Days.daysBetween(EPOCH_DATE, date).getDays(); } }
@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())); }
LocalDate now = LocalDate.now(); LocalDate timeDate = new LocalDate(time); if (Days.daysBetween(now, timeDate).getDays() == 0) {
public List<? extends ProducerJob> partitionJobs() { DateTime start = dateFormatter.parseDateTime(getStartDate()); DateTime end = dateFormatter.parseDateTime(getEndDate()); int days = Days.daysBetween(start, end).getDays(); if (days <= 0) { return new ArrayList<>(); } int step = days / 2; return Arrays.asList(new SimpleProducerJob(getPage(), getStartDate(), dateFormatter.print(start.plusDays(step))), new SimpleProducerJob(getPage(), dateFormatter.print(start.plusDays(step + 1)), getEndDate())); }