List of usage examples for org.joda.time DateTime millisOfSecond
public Property millisOfSecond()
From source file:com.sap.dirigible.runtime.metrics.TimeUtils.java
License:Open Source License
private static DateTime dateTimeCeiling(DateTime dt, Period p) { if (p.getYears() != 0) { return dt.yearOfEra().roundCeilingCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundCeilingCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundCeilingCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundCeilingCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundCeilingCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundCeilingCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundCeilingCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }/*w ww .j a va 2 s .c o m*/ return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }
From source file:com.tikal.tallerWeb.modelo.alerta.RangoAlertaVerificacion.java
License:Apache License
private DateTime armaFechaRangoIzquierdo(int mes, int yearSwift) { DateTime r = new DateTime(); r = new DateTime(r.getYear() + yearSwift, mes, r.dayOfMonth().getMinimumValue(), r.hourOfDay().getMinimumValue(), r.minuteOfHour().getMinimumValue(), r.secondOfMinute().getMinimumValue(), r.millisOfSecond().getMinimumValue(), r.getZone()); r = r.minusDays(diasAntesDelMes);//from w ww . j av a2 s. co m return r; }
From source file:com.tikal.tallerWeb.modelo.alerta.RangoAlertaVerificacion.java
License:Apache License
private DateTime armaFechaRangoDerecho(int mes, int yearSwift) { DateTime r = new DateTime(); r = new DateTime(r.getYear() + yearSwift, mes, r.dayOfMonth().getMinimumValue(), r.hourOfDay().getMinimumValue(), r.minuteOfHour().getMinimumValue(), r.secondOfMinute().getMinimumValue(), r.millisOfSecond().getMinimumValue(), r.getZone()); r = new DateTime(r.getYear(), mes, r.dayOfMonth().getMaximumValue(), r.hourOfDay().getMaximumValue(), r.minuteOfHour().getMaximumValue(), r.secondOfMinute().getMaximumValue(), r.millisOfSecond().getMaximumValue(), r.getZone()); return r;//from w ww .j a v a2 s .c om }
From source file:fi.hsl.parkandride.core.service.reporting.RequestLogInterval.java
License:EUPL
private static DateTime removeSmallPartials(DateTime time) { return time.millisOfSecond().withMinimumValue().secondOfMinute().withMinimumValue().minuteOfHour() .withMinimumValue();/*from w w w . j a v a2s .com*/ }
From source file:nl.basjes.parse.dissectors.http.TimeStampDissector.java
License:Open Source License
@Override public void dissect(final Parsable<?> parsable, final String inputname) throws DissectionFailure { final ParsedField field = parsable.getParsableField(INPUT_TYPE, inputname); final String fieldValue = field.getValue(); if (fieldValue == null || fieldValue.isEmpty()) { return; // Nothing to do here }// ww w. j a va 2 s.c om if (wantAnyAsParsed || wantAnyTZIndependent) { // FIXME: YUCK ! Parsing the same thing TWICE just for the Zone ?!?!? DateTime dateTime = asParsedFormatter.parseDateTime(fieldValue); DateTimeZone zone = dateTime.getZone(); DateTimeFormatter asParsedWithZoneFormatter = asParsedFormatter.withZone(zone); dateTime = asParsedWithZoneFormatter.parseDateTime(fieldValue); // As parsed if (wantDay) { parsable.addDissection(inputname, "TIME.DAY", "day", dateTime.dayOfMonth().getAsString()); } if (wantMonthname) { parsable.addDissection(inputname, "TIME.MONTHNAME", "monthname", dateTime.monthOfYear().getAsText(Locale.getDefault())); } if (wantMonth) { parsable.addDissection(inputname, "TIME.MONTH", "month", dateTime.monthOfYear().getAsString()); } if (wantWeekOfWeekYear) { parsable.addDissection(inputname, "TIME.WEEK", "weekofweekyear", dateTime.weekOfWeekyear().getAsString()); } if (wantWeekYear) { parsable.addDissection(inputname, "TIME.YEAR", "weekyear", dateTime.weekyear().getAsString()); } if (wantYear) { parsable.addDissection(inputname, "TIME.YEAR", "year", dateTime.year().getAsString()); } if (wantHour) { parsable.addDissection(inputname, "TIME.HOUR", "hour", dateTime.hourOfDay().getAsString()); } if (wantMinute) { parsable.addDissection(inputname, "TIME.MINUTE", "minute", dateTime.minuteOfHour().getAsString()); } if (wantSecond) { parsable.addDissection(inputname, "TIME.SECOND", "second", dateTime.secondOfMinute().getAsString()); } if (wantMillisecond) { parsable.addDissection(inputname, "TIME.MILLISECOND", "millisecond", dateTime.millisOfSecond().getAsString()); } // Timezone independent if (wantTimezone) { parsable.addDissection(inputname, "TIME.TIMEZONE", "timezone", dateTime.getZone().getID()); } if (wantEpoch) { parsable.addDissection(inputname, "TIME.EPOCH", "epoch", Long.toString(dateTime.getMillis())); } } if (wantAnyUTC) { // In UTC timezone DateTime dateTime = formatter.parseDateTime(fieldValue); if (wantDayUTC) { parsable.addDissection(inputname, "TIME.DAY", "day_utc", dateTime.dayOfMonth().getAsString()); } if (wantMonthnameUTC) { parsable.addDissection(inputname, "TIME.MONTHNAME", "monthname_utc", dateTime.monthOfYear().getAsText(Locale.getDefault())); } if (wantMonthUTC) { parsable.addDissection(inputname, "TIME.MONTH", "month_utc", dateTime.monthOfYear().getAsString()); } if (wantWeekOfWeekYearUTC) { parsable.addDissection(inputname, "TIME.WEEK", "weekofweekyear_utc", dateTime.weekOfWeekyear().getAsString()); } if (wantWeekYearUTC) { parsable.addDissection(inputname, "TIME.YEAR", "weekyear_utc", dateTime.weekyear().getAsString()); } if (wantYearUTC) { parsable.addDissection(inputname, "TIME.YEAR", "year_utc", dateTime.year().getAsString()); } if (wantHourUTC) { parsable.addDissection(inputname, "TIME.HOUR", "hour_utc", dateTime.hourOfDay().getAsString()); } if (wantMinuteUTC) { parsable.addDissection(inputname, "TIME.MINUTE", "minute_utc", dateTime.minuteOfHour().getAsString()); } if (wantSecondUTC) { parsable.addDissection(inputname, "TIME.SECOND", "second_utc", dateTime.secondOfMinute().getAsString()); } if (wantMillisecondUTC) { parsable.addDissection(inputname, "TIME.MILLISECOND", "millisecond_utc", dateTime.millisOfSecond().getAsString()); } } }
From source file:nl.basjes.parse.httpdlog.dissectors.TimeStampDissector.java
License:Apache License
@Override public void dissect(final Parsable<?> parsable, final String inputname) throws DissectionFailure { final ParsedField field = parsable.getParsableField(INPUT_TYPE, inputname); String fieldValue = field.getValue().getString(); if (fieldValue == null || fieldValue.isEmpty()) { return; // Nothing to do here }//from ww w. j a va 2s .c o m fieldValue = fieldValue.toLowerCase(Locale.getDefault()); if (wantAnyAsParsed || wantAnyTZIndependent) { // YUCK ! Parsing the same thing TWICE just for the Zone ?!?!? DateTime dateTime = asParsedFormatter.parseDateTime(fieldValue); DateTimeZone zone = dateTime.getZone(); DateTimeFormatter asParsedWithZoneFormatter = asParsedFormatter.withZone(zone); dateTime = asParsedWithZoneFormatter.parseDateTime(fieldValue); // As parsed if (wantDay) { parsable.addDissection(inputname, "TIME.DAY", "day", dateTime.dayOfMonth().get()); } if (wantMonthname) { parsable.addDissection(inputname, "TIME.MONTHNAME", "monthname", dateTime.monthOfYear().getAsText(Locale.getDefault())); } if (wantMonth) { parsable.addDissection(inputname, "TIME.MONTH", "month", dateTime.monthOfYear().get()); } if (wantWeekOfWeekYear) { parsable.addDissection(inputname, "TIME.WEEK", "weekofweekyear", dateTime.weekOfWeekyear().get()); } if (wantWeekYear) { parsable.addDissection(inputname, "TIME.YEAR", "weekyear", dateTime.weekyear().get()); } if (wantYear) { parsable.addDissection(inputname, "TIME.YEAR", "year", dateTime.year().get()); } if (wantHour) { parsable.addDissection(inputname, "TIME.HOUR", "hour", dateTime.hourOfDay().get()); } if (wantMinute) { parsable.addDissection(inputname, "TIME.MINUTE", "minute", dateTime.minuteOfHour().get()); } if (wantSecond) { parsable.addDissection(inputname, "TIME.SECOND", "second", dateTime.secondOfMinute().get()); } if (wantMillisecond) { parsable.addDissection(inputname, "TIME.MILLISECOND", "millisecond", dateTime.millisOfSecond().get()); } if (wantDate) { parsable.addDissection(inputname, "TIME.DATE", "date", ISO_DATE_FORMATTER.print(dateTime)); } if (wantTime) { parsable.addDissection(inputname, "TIME.TIME", "time", ISO_TIME_FORMATTER.print(dateTime)); } // Timezone independent if (wantTimezone) { parsable.addDissection(inputname, "TIME.TIMEZONE", "timezone", dateTime.getZone().getID()); } if (wantEpoch) { parsable.addDissection(inputname, "TIME.EPOCH", "epoch", dateTime.getMillis()); } } if (wantAnyUTC) { // In UTC timezone DateTime dateTime = formatter.parseDateTime(fieldValue); if (wantDayUTC) { parsable.addDissection(inputname, "TIME.DAY", "day_utc", dateTime.dayOfMonth().get()); } if (wantMonthnameUTC) { parsable.addDissection(inputname, "TIME.MONTHNAME", "monthname_utc", dateTime.monthOfYear().getAsText(Locale.getDefault())); } if (wantMonthUTC) { parsable.addDissection(inputname, "TIME.MONTH", "month_utc", dateTime.monthOfYear().get()); } if (wantWeekOfWeekYearUTC) { parsable.addDissection(inputname, "TIME.WEEK", "weekofweekyear_utc", dateTime.weekOfWeekyear().get()); } if (wantWeekYearUTC) { parsable.addDissection(inputname, "TIME.YEAR", "weekyear_utc", dateTime.weekyear().get()); } if (wantYearUTC) { parsable.addDissection(inputname, "TIME.YEAR", "year_utc", dateTime.year().get()); } if (wantHourUTC) { parsable.addDissection(inputname, "TIME.HOUR", "hour_utc", dateTime.hourOfDay().get()); } if (wantMinuteUTC) { parsable.addDissection(inputname, "TIME.MINUTE", "minute_utc", dateTime.minuteOfHour().get()); } if (wantSecondUTC) { parsable.addDissection(inputname, "TIME.SECOND", "second_utc", dateTime.secondOfMinute().get()); } if (wantMillisecondUTC) { parsable.addDissection(inputname, "TIME.MILLISECOND", "millisecond_utc", dateTime.millisOfSecond().get()); } if (wantDateUTC) { parsable.addDissection(inputname, "TIME.DATE", "date_utc", ISO_DATE_FORMATTER.print(dateTime)); } if (wantTimeUTC) { parsable.addDissection(inputname, "TIME.TIME", "time_utc", ISO_TIME_FORMATTER.print(dateTime)); } } }
From source file:org.apache.druid.query.expression.TimestampExtractExprMacro.java
License:Apache License
@Override public Expr apply(final List<Expr> args) { if (args.size() < 2 || args.size() > 3) { throw new IAE("Function[%s] must have 2 to 3 arguments", name()); }/*from ww w .j av a 2s. c om*/ if (!args.get(1).isLiteral() || args.get(1).getLiteralValue() == null) { throw new IAE("Function[%s] unit arg must be literal", name()); } if (args.size() > 2 && !args.get(2).isLiteral()) { throw new IAE("Function[%s] timezone arg must be literal", name()); } final Expr arg = args.get(0); final Unit unit = Unit.valueOf(StringUtils.toUpperCase((String) args.get(1).getLiteralValue())); final DateTimeZone timeZone; if (args.size() > 2) { timeZone = ExprUtils.toTimeZone(args.get(2)); } else { timeZone = DateTimeZone.UTC; } final ISOChronology chronology = ISOChronology.getInstance(timeZone); class TimestampExtractExpr extends ExprMacroTable.BaseScalarUnivariateMacroFunctionExpr { private TimestampExtractExpr(Expr arg) { super(arg); } @Nonnull @Override public ExprEval eval(final ObjectBinding bindings) { Object val = arg.eval(bindings).value(); if (val == null) { // Return null if the argument if null. return ExprEval.of(null); } final DateTime dateTime = new DateTime(val, chronology); long epoch = dateTime.getMillis() / 1000; switch (unit) { case EPOCH: return ExprEval.of(epoch); case MICROSECOND: return ExprEval.of(epoch / 1000); case MILLISECOND: return ExprEval.of(dateTime.millisOfSecond().get()); case SECOND: return ExprEval.of(dateTime.secondOfMinute().get()); case MINUTE: return ExprEval.of(dateTime.minuteOfHour().get()); case HOUR: return ExprEval.of(dateTime.hourOfDay().get()); case DAY: return ExprEval.of(dateTime.dayOfMonth().get()); case DOW: return ExprEval.of(dateTime.dayOfWeek().get()); case ISODOW: return ExprEval.of(dateTime.dayOfWeek().get()); case DOY: return ExprEval.of(dateTime.dayOfYear().get()); case WEEK: return ExprEval.of(dateTime.weekOfWeekyear().get()); case MONTH: return ExprEval.of(dateTime.monthOfYear().get()); case QUARTER: return ExprEval.of((dateTime.monthOfYear().get() - 1) / 3 + 1); case YEAR: return ExprEval.of(dateTime.year().get()); case ISOYEAR: return ExprEval.of(dateTime.year().get()); case DECADE: // The year field divided by 10, See https://www.postgresql.org/docs/10/functions-datetime.html return ExprEval.of(Math.floor(dateTime.year().get() / 10)); case CENTURY: return ExprEval.of(dateTime.centuryOfEra().get() + 1); case MILLENNIUM: // Years in the 1900s are in the second millennium. The third millennium started January 1, 2001. // See https://www.postgresql.org/docs/10/functions-datetime.html return ExprEval.of(Math.round(Math.ceil(dateTime.year().get() / 1000))); default: throw new ISE("Unhandled unit[%s]", unit); } } @Override public Expr visit(Shuttle shuttle) { Expr newArg = arg.visit(shuttle); return shuttle.visit(new TimestampExtractExpr(newArg)); } } return new TimestampExtractExpr(arg); }
From source file:org.apache.pig.piggybank.evaluation.datetime.truncate.ISOToSecond.java
License:Apache License
@Override public String exec(Tuple input) throws IOException { if (input == null || input.size() < 1) { return null; }/*from w w w. ja v a2s . co m*/ DateTime dt = ISOHelper.parseDateTime(input); // Set the the second and milliseconds to 0 DateTime result = dt.millisOfSecond().setCopy(0); return result.toString(); }
From source file:org.hawkular.metrics.core.impl.DateTimeService.java
License:Apache License
public DateTime getTimeSlice(DateTime dt, Duration duration) { Period p = duration.toPeriod(); if (p.getYears() != 0) { return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }// w ww . jav a 2 s. co m return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }
From source file:org.hawkular.metrics.datetime.DateTimeService.java
License:Apache License
public static DateTime getTimeSlice(DateTime dt, Duration duration) { Period p = duration.toPeriod(); if (p.getYears() != 0) { return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }/*w w w . j a va 2 s. c o m*/ return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }