private static DateTime getDayBucket(DateTime observationTime) { return observationTime.withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0); }
private DateTime parseDateTime(final String scheduleDate, final String scheduleTime) { // scheduleTime: 12,00,pm,PDT final String[] parts = scheduleTime.split(",", -1); int hour = Integer.parseInt(parts[0]); final int minutes = Integer.parseInt(parts[1]); final boolean isPm = parts[2].equalsIgnoreCase("pm"); final DateTimeZone timezone = parts[3].equals("UTC") ? DateTimeZone.UTC : DateTimeZone.getDefault(); // scheduleDate: 02/10/2013 DateTime day = null; if (scheduleDate == null || scheduleDate.trim().length() == 0) { day = new LocalDateTime().toDateTime(); } else { day = DateTimeFormat.forPattern("MM/dd/yyyy") .withZone(timezone).parseDateTime(scheduleDate); } hour %= 12; if (isPm) { hour += 12; } final DateTime firstSchedTime = day.withHourOfDay(hour).withMinuteOfHour(minutes).withSecondOfMinute(0); return firstSchedTime; }
@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); } } } }
case SECONDS: _dateTimeTruncate = (dateTime) -> _outputDateTimeFormatter.print( dateTime.withSecondOfMinute((dateTime.getSecondOfMinute() / sz) * sz).secondOfMinute().roundFloorCopy()); break; case MINUTES:
dt = dt.withHourOfDay(0); dt = dt.withMinuteOfHour(0); dt = dt.withSecondOfMinute(0); default: dt = dt.withMillisOfSecond(0);
queryStr = StringUtils.replace(queryStr, "%%POST_AG_REQUEST_START%%", INTERVAL_FMT.print(dtFirst)); queryStr = StringUtils.replace(queryStr, "%%POST_AG_REQUEST_END%%", INTERVAL_FMT.print(dtLast.plusMinutes(2))); String postAgResponseTimestamp = TIMESTAMP_FMT.print(dtGroupBy.withSecondOfMinute(0)); queryStr = StringUtils.replace(queryStr, "%%POST_AG_RESPONSE_TIMESTAMP%%", postAgResponseTimestamp); queryStr = StringUtils.replace(queryStr, "%%DATASOURCE%%", fullDatasourceName);
public RFC5545Schedule(String schedule) throws InvalidRecurrenceRuleException { // DTSTART is RFC5545 but NOT in the recur string, but its a nice to have? :) Pattern pattern = Pattern.compile("DTSTART=([0-9]{8}T[0-9]{6})"); Matcher matcher = pattern.matcher(schedule); if (matcher.find()) { DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd'T'HHmmss"); this.dtStart = formatter.parseDateTime(matcher.group(1)); this.recurrenceRule = new RecurrenceRule(matcher.replaceAll("").replace("RRULE:", "")); } else { this.recurrenceRule = new RecurrenceRule(schedule); this.dtStart = org.joda.time.DateTime.now().withSecondOfMinute(0); } }
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); }
assertFunction("date_trunc('second', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session)); result = result.withSecondOfMinute(0); assertFunction("date_trunc('minute', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session)); assertFunction("date_trunc('second', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result)); result = result.withSecondOfMinute(0); assertFunction("date_trunc('minute', " + 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); }
@Override public LongLongPair startEnd(long time) { DateTime dt = new DateTime(time); DateTime start = dt.withSecondOfMinute(0); DateTime end = dt.plus(minutePeriod).withSecondOfMinute(0); return LongLongPair.pair(start.getMillis(), end.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()); } }
private Interval extractSearchInterval(final Entity contextEntity) { Date from = contextEntity.getDateField(BalanceContextFields.FROM_DATE); Date to = contextEntity.getDateField(BalanceContextFields.TO_DATE); DateTime toMidnight = new DateTime(to).withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59); return new Interval(new DateTime(from), toMidnight); }
/** * 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); }
/** * 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 int getDuration(DateTime now, DateTime expiryDate) { Interval interval = new Interval(now.withSecondOfMinute(0).withMillisOfSecond(0), expiryDate); return interval.toPeriod(PeriodType.days()).getDays(); }
@Override int getDuration(DateTime now, DateTime expiryDate) { Interval interval = new Interval(now.withSecondOfMinute(0).withMillisOfSecond(0), expiryDate); return interval.toPeriod(PeriodType.hours()).getHours(); }