List of usage examples for org.joda.time Period days
public static Period days(int days)
From source file:org.apache.calcite.adapter.druid.DruidSqlCastConverter.java
License:Apache License
private static String castCharToDateTime(TimeZone timeZone, String operand, final SqlTypeName toType, String format) {/*from ww w. j av a 2s . c om*/ // Cast strings to date times by parsing them from SQL format. final String timestampExpression = DruidExpressions.functionCall("timestamp_parse", ImmutableList.of( operand, DruidExpressions.stringLiteral(format), DruidExpressions.stringLiteral(timeZone.getID()))); if (toType == SqlTypeName.DATE) { // case to date we need to floor to day first return DruidExpressions.applyTimestampFloor(timestampExpression, Period.days(1).toString(), "", timeZone); } else if (toType == SqlTypeName.TIMESTAMP || toType == SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE) { return timestampExpression; } else { throw new IllegalStateException(DruidQuery.format("Unsupported DateTime type[%s]", toType)); } }
From source file:org.apache.drill.common.expression.ExpressionStringBuilder.java
License:Apache License
@Override public Void visitIntervalDayConstant(IntervalDayExpression lExpr, StringBuilder sb) throws RuntimeException { sb.append("cast( '"); sb.append(Period.days(lExpr.getIntervalDay()).plusMillis(lExpr.getIntervalMillis()).toString()); sb.append("' as INTERVALDAY)"); return null;/*from w w w . ja v a 2s. c o m*/ }
From source file:org.apache.drill.test.rowSet.RowSetUtilities.java
License:Apache License
/** * Ad-hoc, test-only method to set a Period from an integer. Periods are made up of * months and millseconds. There is no mapping from one to the other, so a period * requires at least two number. Still, we are given just one (typically from a test * data generator.) Use that int value to "spread" some value across the two kinds * of fields. The result has no meaning, but has the same comparison order as the * original ints.//from w w w .j av a 2 s .c om * * @param writer column writer for a period column * @param minorType the Drill data type * @param value the integer value to apply * @throws VectorOverflowException */ public static Period periodFromInt(MinorType minorType, int value) { switch (minorType) { case INTERVAL: return Duration.millis(value).toPeriod(); case INTERVALYEAR: return Period.years(value / 12).withMonths(value % 12); case INTERVALDAY: int sec = value % 60; value = value / 60; int min = value % 60; value = value / 60; return Period.days(value).withMinutes(min).withSeconds(sec); default: throw new IllegalArgumentException("Writer is not an interval: " + minorType); } }
From source file:org.apache.druid.sql.calcite.expression.builtin.TimeFloorOperatorConversion.java
License:Apache License
/** * Function that floors a DruidExpression to a particular granularity. Not actually used by the * TimeFloorOperatorConversion, but I'm not sure where else to put this. It makes some sense in this file, since * it's responsible for generating "timestamp_floor" calls. *//*from ww w . j a va 2 s . c o m*/ public static DruidExpression applyTimestampFloor(final DruidExpression input, final PeriodGranularity granularity, final ExprMacroTable macroTable) { Preconditions.checkNotNull(input, "input"); Preconditions.checkNotNull(granularity, "granularity"); // Collapse floor chains if possible. Useful for constructs like CAST(FLOOR(__time TO QUARTER) AS DATE). if (granularity.getPeriod().equals(Period.days(1))) { final TimestampFloorExprMacro.TimestampFloorExpr floorExpr = Expressions.asTimestampFloorExpr(input, macroTable); if (floorExpr != null) { final PeriodGranularity inputGranularity = floorExpr.getGranularity(); if (Objects.equals(inputGranularity.getTimeZone(), granularity.getTimeZone()) && Objects.equals(inputGranularity.getOrigin(), granularity.getOrigin()) && periodIsDayMultiple(inputGranularity.getPeriod())) { return input; } } } return DruidExpression.fromFunctionCall("timestamp_floor", ImmutableList .of(input.getExpression(), DruidExpression.stringLiteral(granularity.getPeriod().toString()), DruidExpression.numberLiteral(granularity.getOrigin() == null ? null : granularity.getOrigin().getMillis()), DruidExpression.stringLiteral(granularity.getTimeZone().toString())) .stream().map(DruidExpression::fromExpression).collect(Collectors.toList())); }
From source file:org.isisaddons.module.fakedata.dom.JodaPeriods.java
License:Apache License
@Programmatic public Period daysBetween(final int minDays, final int maxDays) { return Period.days(fake.ints().between(minDays, maxDays)); }
From source file:org.jevis.commons.dataprocessing.Options.java
License:Open Source License
/** * Returns an list of intervals//from w ww . j a va 2 s. c o m * * @param task * @param from * @param until * @return */ public static List<Interval> getIntervals(Task task, DateTime from, DateTime until) { Period period = Period.days(1); DateTime offset = new DateTime(2001, 01, 01, 00, 00, 00); if (!task.getOptions().containsKey(PERIOD)) { System.out.println("Error missing period option"); } if (!task.getOptions().containsKey(OFFSET)) { System.out.println("Error missing offset option"); task.getOptions().put(OFFSET, "2001-01-01 00:00:00"); } for (Map.Entry<String, String> entry : task.getOptions().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); System.out.println("key: " + key); switch (key) { case PERIOD: System.out.println("period string: " + value); period = Period.parse(value); System.out.println("pared period: " + period); break; case OFFSET: //TODO check value formate DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); offset = dtf.parseDateTime(value); break; } } return buildIntervals(period, offset, from, until); }
From source file:org.jevis.commons.dataprocessing.ProcessOptions.java
License:Open Source License
/** * Returns an list of intervals//from ww w . ja va 2s. c o m * * @param task * @param from * @param until * @return */ public static List<Interval> getIntervals(Process task, DateTime from, DateTime until) { Period period = Period.days(1); DateTime offset = new DateTime(2001, 01, 01, 00, 00, 00); if (ContainsOption(task, PERIOD)) { System.out.println("Error missing period option"); } if (ContainsOption(task, OFFSET)) { System.out.println("Error missing offset option"); task.getOptions().add(new BasicProcessOption(OFFSET, "2001-01-01 00:00:00")); } for (ProcessOption option : task.getOptions()) { String key = option.getKey(); String value = option.getValue(); System.out.println("key: " + key); switch (key) { case PERIOD: System.out.println("period string: " + value); period = Period.parse(value); System.out.println("pared period: " + period); break; case OFFSET: //TODO check value formate DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); offset = dtf.parseDateTime(value); break; } } return buildIntervals(period, offset, from, until); }
From source file:org.jevis.jeconfig.sample.SampleEditor.java
License:Open Source License
/** * * @param att// w w w .jav a 2s . co m * @param from * @param until * @param extensions */ private void updateSamples(final JEVisAttribute att, final DateTime from, final DateTime until, List<SampleEditorExtension> extensions) { System.out.println("update samples"); try { samples.clear(); _from = from; _until = until; if (_dataProcessor != null) { Options.setStartEnd(_dataProcessor, _from, _until, true, true); _dataProcessor.restResult(); } Task aggrigate = null; if (_mode == AGGREGATION.None) { } else if (_mode == AGGREGATION.Daily) { aggrigate = new TaskImp(); aggrigate.setJEVisDataSource(att.getDataSource()); aggrigate.setID("Dynamic"); aggrigate.setProcessor(new AggrigatorProcessor()); aggrigate.addOption(Options.PERIOD, Period.days(1).toString()); } else if (_mode == AGGREGATION.Monthly) { aggrigate = new TaskImp(); aggrigate.setJEVisDataSource(att.getDataSource()); aggrigate.setID("Dynamic"); aggrigate.setProcessor(new AggrigatorProcessor()); aggrigate.addOption(Options.PERIOD, Period.months(1).toString()); } else if (_mode == AGGREGATION.Weekly) { aggrigate = new TaskImp(); aggrigate.setJEVisDataSource(att.getDataSource()); aggrigate.setID("Dynamic"); aggrigate.setProcessor(new AggrigatorProcessor()); aggrigate.addOption(Options.PERIOD, Period.weeks(1).toString()); } else if (_mode == AGGREGATION.Yearly) { System.out.println("year..... " + Period.years(1).toString()); aggrigate = new TaskImp(); aggrigate.setJEVisDataSource(att.getDataSource()); aggrigate.setID("Dynamic"); aggrigate.setProcessor(new AggrigatorProcessor()); aggrigate.addOption(Options.PERIOD, Period.years(1).toString()); } if (_dataProcessor == null) { if (aggrigate != null) { Task input = new TaskImp(); input.setJEVisDataSource(att.getDataSource()); input.setID("Dynamic Input"); input.setProcessor(new InputProcessor()); input.getOptions().put(InputProcessor.ATTRIBUTE_ID, _attribute.getName()); input.getOptions().put(InputProcessor.OBJECT_ID, _attribute.getObject().getID() + ""); aggrigate.setSubTasks(Arrays.asList(input)); samples.addAll(aggrigate.getResult()); } else { samples.addAll(att.getSamples(from, until)); } } else { if (aggrigate != null) { aggrigate.setSubTasks(Arrays.asList(_dataProcessor)); samples.addAll(aggrigate.getResult()); } else { samples.addAll(_dataProcessor.getResult()); } } for (SampleEditorExtension ex : extensions) { ex.setSamples(att, samples); } _dataChanged = true; _visibleExtension.update(); } catch (JEVisException ex) { ex.printStackTrace(); } }
From source file:org.kalypso.commons.time.PeriodUtils.java
License:Open Source License
public static Period getPeriod(final int calendarField, final int amount) { switch (calendarField) { case Calendar.YEAR: return Period.years(amount); case Calendar.MONTH: return Period.months(amount); case Calendar.WEEK_OF_YEAR: case Calendar.WEEK_OF_MONTH: return Period.weeks(amount); case Calendar.DAY_OF_MONTH: case Calendar.DAY_OF_YEAR: case Calendar.DAY_OF_WEEK: case Calendar.DAY_OF_WEEK_IN_MONTH: return Period.days(amount); case Calendar.HOUR: case Calendar.HOUR_OF_DAY: return Period.hours(amount); case Calendar.MINUTE: return Period.minutes(amount); case Calendar.SECOND: return Period.seconds(amount); case Calendar.MILLISECOND: return Period.millis(amount); case Calendar.AM_PM: case Calendar.ERA: default:/*from w w w .j ava2 s . c o m*/ throw new UnsupportedOperationException(); } }
From source file:org.kalypso.ui.rrm.internal.conversion.to12_02.RepairTimeseriesOperation.java
License:Open Source License
private boolean isTageszeitreihe() { return Objects.equal(m_timestep, Period.days(1)); }