private static DateTime getDayBucket(DateTime observationTime) { return observationTime.withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0); }
@Override public void run() { DescriptiveStatistics stats = this.limiter.getRateStatsSinceLastReport(); long now = System.currentTimeMillis(); this.runs++; if (stats != null) { long key; if (this.relativeKey) { key = 15 * this.runs; } else { DateTime nowTime = new DateTime(now).withMillisOfSecond(0); DateTime rounded = nowTime.withSecondOfMinute(15 * (nowTime.getSecondOfMinute() / 15)); key = rounded.getMillis() / 1000; } try { this.context.write(new LongWritable(key), new DoubleWritable(stats.getSum())); } catch (IOException | InterruptedException ioe) { log.error("Error: ", ioe); } } } }
DateTime now = DateTime.now(time.getZone()).withMillisOfSecond(0); DateTime timeDt = new DateTime(time).withMillisOfSecond(0); boolean past = !now.isBefore(timeDt); Duration duration = past ? new Duration(timeDt, now) : new Duration(now, timeDt);
case MILLISECONDS: _dateTimeTruncate = (dateTime) -> _outputDateTimeFormatter .print(dateTime.withMillisOfSecond((dateTime.getMillisOfSecond() / sz) * sz)); break; case SECONDS:
dt = dt.withSecondOfMinute(0); default: dt = dt.withMillisOfSecond(0); break;
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);
private DateTime extractAndUpdateTime(DateTime inputDateTime) { DateTime resultDateTime = inputDateTime.withSecondOfMinute(0).withMillisOfSecond(0); if (dateTime.equals("") || dateTime.contains("now")) return resultDateTime; int hour = 0; int minute = 0; Pattern p = Pattern.compile("(\\d{1,2}):(\\d{2})([a|p]m)?(.*)"); Matcher m = p.matcher(dateTime); if (m.matches()) { hour = Integer.parseInt(m.group(1)); minute = Integer.parseInt(m.group(2)); String middayModifier = m.group(3); if (middayModifier != null && middayModifier.equals("pm")) hour = (hour + 12) % 24; dateTime = m.group(4); } if (dateTime.contains("noon")) { hour = 12; dateTime = dateTime.replace("noon", ""); } else if (dateTime.contains("teatime")) { hour = 16; dateTime = dateTime.replace("teatime", ""); } else if (dateTime.contains("midnight")) dateTime = dateTime.replace("midnight", ""); return resultDateTime.withHourOfDay(hour).withMinuteOfHour(minute); }
result = result.withMillisOfSecond(0); assertFunction("date_trunc('second', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session)); result = result.withMillisOfSecond(0); assertFunction("date_trunc('second', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));
private static DateTime nowDateTime() { return new DateTime().withSecondOfMinute(0).withMillisOfSecond(0); }
@Before public void setup() { nowDateTime = new DateTime().withSecondOfMinute(0).withMillisOfSecond(0); }
private static DateTime referenceDateTime() { return new DateTime().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0); }
protected DateTime now() { DateTime dt = highPrecision ? DateTime.now() : DateTime.now().withMillisOfSecond(0); return 0 == delta ? dt : dt.plusSeconds(delta); } }
@Override public long applyAsLong(long operand) { return new DateTime(operand,tz).withMillisOfSecond(0).withSecondOfMinute(0).getMillis(); } }
@Override public long applyAsLong(long operand) { return new DateTime(operand,tz).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0).getMillis(); } }
public static Intent createNewEventIntent(DateTimeZone timeZone) { DateTime beginTime = new DateTime(timeZone).plusHours(1).withMinuteOfHour(0).withSecondOfMinute(0) .withMillisOfSecond(0); DateTime endTime = beginTime.plusHours(1); return new Intent(Intent.ACTION_INSERT, Events.CONTENT_URI) .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getMillis()) .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getMillis()); } }
/** * Returns a random timestamp. */ public static DateTime getRandomDateTime() { return new DateTime(new Random().nextLong()).withMillisOfSecond(0); }
/** * Parse the to date query param. */ private DateTime parseFromDate(String fromDate) { // Default to the last 30 days DateTime defaultFrom = new DateTime().withZone(DateTimeZone.UTC).minusDays(30).withHourOfDay(0) .withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0); return parseDate(fromDate, defaultFrom, true); }
@Override public int getDuration(DateTime now, DateTime expiryDate) { Interval interval = new Interval(now.withMillisOfSecond(0), expiryDate); return interval.toPeriod(PeriodType.minutes()).getMinutes(); }
private static RubyDateTime calcAjdFromCivil(ThreadContext context, final DateTime dt, final int off, final long subMillisNum, final long subMillisDen) { final Ruby runtime = context.runtime; long jd = civil_to_jd(dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth(), ITALY); RubyNumeric fr = timeToDayFraction(context, dt.getHourOfDay(), dt.getMinuteOfHour(), dt.getSecondOfMinute()); final RubyNumeric ajd = jd_to_ajd(context, jd, fr, off); RubyDateTime dateTime = new RubyDateTime(context, getDateTime(runtime), ajd, off, ITALY); dateTime.dt = dateTime.dt.withMillisOfSecond(dt.getMillisOfSecond()); dateTime.subMillisNum = subMillisNum; dateTime.subMillisDen = subMillisDen; return dateTime; }
private static RubyDateTime calcAjdFromCivil(ThreadContext context, final DateTime dt, final int off, final long subMillisNum, final long subMillisDen) { final Ruby runtime = context.runtime; long jd = civil_to_jd(dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth(), ITALY); RubyNumeric fr = timeToDayFraction(context, dt.getHourOfDay(), dt.getMinuteOfHour(), dt.getSecondOfMinute()); final RubyNumeric ajd = jd_to_ajd(context, jd, fr, off); RubyDateTime dateTime = new RubyDateTime(context, getDateTime(runtime), ajd, off, ITALY); dateTime.dt = dateTime.dt.withMillisOfSecond(dt.getMillisOfSecond()); dateTime.subMillisNum = subMillisNum; dateTime.subMillisDen = subMillisDen; return dateTime; }