List of usage examples for org.joda.time DateTime withZone
public DateTime withZone(DateTimeZone newZone)
From source file:org.apache.druid.sql.calcite.planner.Calcites.java
License:Apache License
/** * Calcite expects DATE literals to be represented by DateStrings in the local time zone. * * @param dateTime joda timestamp/*w ww. j a va 2s.c o m*/ * @param timeZone session time zone * * @return Calcite style Calendar, appropriate for literals */ public static DateString jodaToCalciteDateString(final DateTime dateTime, final DateTimeZone timeZone) { return new DateString(CALCITE_DATE_PRINTER.print(dateTime.withZone(timeZone))); }
From source file:org.apache.druid.sql.calcite.planner.PlannerContext.java
License:Apache License
public static PlannerContext create(final DruidOperatorTable operatorTable, final ExprMacroTable macroTable, final PlannerConfig plannerConfig, final Map<String, Object> queryContext, final AuthenticationResult authenticationResult) { final DateTime utcNow; final DateTimeZone timeZone; if (queryContext != null) { final Object tsParam = queryContext.get(CTX_SQL_CURRENT_TIMESTAMP); final Object tzParam = queryContext.get(CTX_SQL_TIME_ZONE); if (tsParam != null) { utcNow = new DateTime(tsParam, DateTimeZone.UTC); } else {/*w w w. ja v a 2s . c o m*/ utcNow = new DateTime(DateTimeZone.UTC); } if (tzParam != null) { timeZone = DateTimes.inferTzFromString(String.valueOf(tzParam)); } else { timeZone = plannerConfig.getSqlTimeZone(); } } else { utcNow = new DateTime(DateTimeZone.UTC); timeZone = plannerConfig.getSqlTimeZone(); } return new PlannerContext(operatorTable, macroTable, plannerConfig.withOverrides(queryContext), utcNow.withZone(timeZone), queryContext, authenticationResult); }
From source file:org.apache.solr.update.processor.ParseDateFieldUpdateProcessorFactory.java
License:Apache License
@Override public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) {//from ww w.ja v a 2 s .c om return new AllValuesOrNoneFieldMutatingUpdateProcessor(getSelector(), next) { @Override protected Object mutateValue(Object srcVal) { if (srcVal instanceof CharSequence) { String srcStringVal = srcVal.toString(); for (Map.Entry<String, DateTimeFormatter> format : formats.entrySet()) { DateTimeFormatter parser = format.getValue(); try { DateTime dateTime = parser.parseDateTime(srcStringVal); return dateTime.withZone(DateTimeZone.UTC).toDate(); } catch (IllegalArgumentException e) { log.debug("value '{}' is not parseable with format '{}'", new Object[] { srcStringVal, format.getKey() }); } } log.debug("value '{}' was not parsed by any configured format, thus was not mutated", srcStringVal); return SKIP_FIELD_VALUE_LIST_SINGLETON; } if (srcVal instanceof Date) { return srcVal; } return SKIP_FIELD_VALUE_LIST_SINGLETON; } }; }
From source file:org.biokoframework.system.repository.sql.translator.annotation.impl.HSQLDBDateTimeTranslator.java
License:Open Source License
@Override public String convertFromDBValue(String fieldName, ResultSet resultset, Field fieldAnnotation) throws SQLException { String sqlFieldValue = resultset.getString(fieldName); if (sqlFieldValue == null) { return null; } else {// ww w .j a v a 2 s . com DateTime timestamp = DateTimeFormat.forPattern(MYSQL_TIMESTAMP).parseDateTime(sqlFieldValue); timestamp = timestamp.withZone(DateTimeZone.forOffsetHours(1)); return timestamp.toString(ISO_TIMESTAMP); } }
From source file:org.cleverbus.common.jaxb.JaxbDateAdapter.java
License:Apache License
@Nullable public static String printDateTime(@Nullable DateTime dt) { if (dt == null) { return null; }//from w w w . j ava2s . c o m return dt.withZone(DateTimeZone.getDefault()).toString(ISODateTimeFormat.dateTime()); }
From source file:org.everit.jira.timetracker.plugin.util.DateTimeConverterUtil.java
License:Apache License
/** * Convert the give date to the system TimeZone. * * @param date/* w w w .j av a 2s.c om*/ * The origonal date * @return The date in the System TimeZone. */ public static DateTime convertDateZoneToSystemTimeZone(final DateTime date) { DateTime inSystemTimeZone = date.withZone(TimetrackerUtil.getSystemTimeZone()); return inSystemTimeZone; }
From source file:org.everit.jira.timetracker.plugin.util.DateTimeConverterUtil.java
License:Apache License
/** * Convert the give date to the user TimeZone. * * @param date/*from w ww . j a v a 2 s . co m*/ * The origonal date * @return The date in the User TimeZone. */ public static DateTime convertDateZoneToUserTimeZone(final DateTime date) { DateTime inUserTimeZone = date.withZone(TimetrackerUtil.getLoggedUserTimeZone()); return inUserTimeZone; }
From source file:org.graylog2.jackson.MongoJodaDateTimeSerializer.java
License:Open Source License
@Override public void serialize(DateTime dateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { final Date date = dateTime.withZone(DateTimeZone.UTC).toDate(); jsonGenerator.writeObject(date);//from ww w .ja va2 s . c om }
From source file:org.greencheek.related.indexing.util.JodaISO8601UTCCurrentDateAndTimeFormatter.java
License:Apache License
@Override public String getCurrentDay() { DateTime dt = new DateTime(); DateTime utc = dt.withZone(DateTimeZone.UTC); StringBuilderWriter b = new StringBuilderWriter(24); try {/* www. j a va2s. c o m*/ formatter.printTo(b, utc); } catch (IOException e) { // this does not get thrown by the StringBuilder Appendable interface. } return b.toString(); }
From source file:org.greencheek.related.indexing.util.JodaUTCCurrentDateAndHourAndMinuteFormatter.java
License:Apache License
@Override public String getCurrentDayAndHourAndMinute() { DateTime dt = new DateTime(); DateTime utc = dt.withZone(DateTimeZone.UTC); return formatter.print(utc); }