List of usage examples for org.joda.time DateTime toDateTime
public DateTime toDateTime(Chronology chronology)
this
if possible. From source file:eu.trentorise.opendata.jackan.ckan.CkanResource.java
License:Apache License
/** * Internally the date is stored with UTC timezone *//*from w w w . j a v a 2s .c o m*/ public void setWebstoreLastUpdated(@Nullable DateTime webstoreLastUpdated) { if (webstoreLastUpdated != null) { this.webstoreLastUpdated = webstoreLastUpdated.toDateTime(DateTimeZone.UTC); } else { this.webstoreLastUpdated = null; } }
From source file:eu.trentorise.opendata.jackan.ckan.CkanTag.java
License:Apache License
public void setRevisionTimestamp(@Nullable DateTime revisionTimestamp) { if (revisionTimestamp != null) { this.revisionTimestamp = revisionTimestamp.toDateTime(DateTimeZone.UTC); } else {//from w w w . jav a 2 s . co m this.revisionTimestamp = null; } }
From source file:fi.helsinki.opintoni.service.TimeService.java
License:Open Source License
public String toHelsinkiTimeFromUTC(DateTime dateTime) { return dateTime.toDateTime(DateTimeZone.forTimeZone(TimeZone.getTimeZone(HELSINKI_ZONE_ID))) .toString("dd.MM.yyyy HH:mm"); }
From source file:fixtures.bodyinteger.implementation.IntsImpl.java
License:Open Source License
/** * Put datetime encoded as Unix time./*from ww w .j a v a 2 s .co m*/ * * @param intBody the long value * @return the {@link ServiceResponse} object if successful. */ public Observable<ServiceResponse<Void>> putUnixTimeDateWithServiceResponseAsync(DateTime intBody) { Long intBodyConverted = intBody.toDateTime(DateTimeZone.UTC).getMillis() / 1000; return service.putUnixTimeDate(intBodyConverted) .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() { @Override public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) { try { ServiceResponse<Void> clientResponse = putUnixTimeDateDelegate(response); return Observable.just(clientResponse); } catch (Throwable t) { return Observable.error(t); } } }); }
From source file:fixtures.url.implementation.PathsImpl.java
License:Open Source License
/** * Get the date 2016-04-13 encoded value as '1460505600' (Unix time). * * @param unixTimeUrlPath Unix time encoded value * @return the {@link ServiceResponse} object if successful. */// w ww . j a v a 2 s. c o m public Observable<ServiceResponse<Void>> unixTimeUrlWithServiceResponseAsync(DateTime unixTimeUrlPath) { Long unixTimeUrlPathConverted = unixTimeUrlPath.toDateTime(DateTimeZone.UTC).getMillis() / 1000; return service.unixTimeUrl(unixTimeUrlPathConverted) .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() { @Override public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) { try { ServiceResponse<Void> clientResponse = unixTimeUrlDelegate(response); return Observable.just(clientResponse); } catch (Throwable t) { return Observable.error(t); } } }); }
From source file:google.registry.tools.server.GenerateZoneFilesAction.java
License:Open Source License
@Override public Map<String, Object> handleJsonRequest(Map<String, ?> json) { @SuppressWarnings("unchecked") ImmutableSet<String> tlds = ImmutableSet.copyOf((List<String>) json.get("tlds")); final DateTime exportTime = DateTime.parse(json.get("exportTime").toString()); // We disallow exporting within the past 2 minutes because there might be outstanding writes. // We can only reliably call loadAtPointInTime at times that are UTC midnight and > // datastoreRetention ago in the past. DateTime now = clock.nowUtc();/*ww w. jav a 2s.c o m*/ if (exportTime.isAfter(now.minusMinutes(2))) { throw new BadRequestException("Invalid export time: must be > 2 minutes ago"); } if (exportTime.isBefore(now.minus(datastoreRetention))) { throw new BadRequestException(String.format("Invalid export time: must be < %d days ago", datastoreRetention.getStandardDays())); } if (!exportTime.equals(exportTime.toDateTime(UTC).withTimeAtStartOfDay())) { throw new BadRequestException("Invalid export time: must be midnight UTC"); } String jobId = mrRunner.setJobName("Generate bind file stanzas").setModuleName("tools") .setDefaultReduceShards(tlds.size()).runMapreduce(new GenerateBindFileMapper(tlds, exportTime), new GenerateBindFileReducer(bucket, exportTime, gcsBufferSize), ImmutableList.of(new NullInput<EppResource>(), createEntityInput(DomainResource.class, HostResource.class))); ImmutableList<String> filenames = FluentIterable.from(tlds).transform(new Function<String, String>() { @Override public String apply(String tld) { return String.format(GCS_PATH_FORMAT, bucket, String.format(FILENAME_FORMAT, tld, exportTime)); } }).toList(); return ImmutableMap.<String, Object>of("jobPath", createJobPath(jobId), "filenames", filenames); }
From source file:google.registry.xml.UtcDateTimeAdapter.java
License:Open Source License
/** Same as {@link #marshal(DateTime)}, but in a convenient static format. */ public static String getFormattedString(@Nullable DateTime timestamp) { if (timestamp == null) { return ""; }/* w ww .j ava 2 s.co m*/ return MARSHAL_FORMAT.print(timestamp.toDateTime(UTC)); }
From source file:imas.planning.entity.FlightEntity.java
private String convertTimezone(Date date, String countryName) { DateTime original = new DateTime(date.getTime()); DateTimeZone dtz = DateTimeZone.getDefault(); original.withZone(dtz);//w w w . j a va 2 s .c om Set<String> tzIds = DateTimeZone.getAvailableIDs(); for (String timeZoneId : tzIds) { if (timeZoneId.contains(countryName)) { dtz = DateTimeZone.forID(timeZoneId); break; } } DateTime dt = original.toDateTime(dtz); DateTimeFormatter dtfOut = DateTimeFormat.forPattern("MMM dd yyyy HH:mm:ss zzz"); return dtfOut.print(dt); }
From source file:it.webappcommon.lib.DateUtils.java
License:Open Source License
/** * /* w ww . ja v a2 s . c om*/ * @param _fromDate * @param _fromTime * @param _toDate * @param _toTime * @return */ public static Double calculateDuration(Date _fromDate, Date _fromTime, Date _toDate, Date _toTime) { Double duration; Calendar calFromDate = null; Calendar calFromTime = null; Calendar calToDate = null; Calendar calToTime = null; Date fromDateTime = null; Date toDateTime = null; try { if ((_fromDate != null) && (_fromTime != null) && (_toDate != null) && (_toTime != null)) { logger.debug(String.format("%s=%s", _fromDate, _fromDate.getTime())); logger.debug(String.format("%s=%s", _fromTime, _fromTime.getTime())); logger.debug(String.format("%s=%s", _toDate, _toDate.getTime())); logger.debug(String.format("%s=%s", _toTime, _toTime.getTime())); // calFromDate = new GregorianCalendar(); // calFromDate.setTime(_fromDate); // calFromTime = new GregorianCalendar(); // calFromTime.setTime(_fromTime); // calToDate = new GregorianCalendar(); // calToDate.setTime(_toDate); // calToTime = new GregorianCalendar(); // calToTime.setTime(_toTime); // calFromDate.set(Calendar.HOUR_OF_DAY, // calFromTime.get(Calendar.HOUR_OF_DAY)); // calFromDate.set(Calendar.MINUTE, // calFromTime.get(Calendar.MINUTE)); // calFromDate.set(Calendar.SECOND, // calFromTime.get(Calendar.SECOND)); // calFromDate.set(Calendar.MILLISECOND, // calFromTime.get(Calendar.MILLISECOND)); // // calToDate.set(Calendar.HOUR_OF_DAY, // calToTime.get(Calendar.HOUR_OF_DAY)); // calToDate.set(Calendar.MINUTE, // calToTime.get(Calendar.MINUTE)); // calToDate.set(Calendar.SECOND, // calToTime.get(Calendar.SECOND)); // calToDate.set(Calendar.MILLISECOND, // calToTime.get(Calendar.MILLISECOND)); // calFromDate.setTime(mergeDateTime(_fromDate, _fromTime)); // calToDate.setTime(mergeDateTime(_toDate, _toTime)); // fromDateTime = calFromDate.getTime(); // toDateTime = calToDate.getTime(); // logger.debug(String.format("%s=%s", fromDateTime, // fromDateTime.getTime())); // logger.debug(String.format("%s=%s", toDateTime, // fromDateTime.getTime())); // duration = ((toDateTime.getTime() - fromDateTime.getTime()) / // 1000d / 60d / 60d); // DateTime a = new DateTime(mergeDateTime(_fromDate, // _fromTime)); // DateTime b = new DateTime(mergeDateTime(_toDate, _toTime)); // LocalDateTime a1 = new LocalDateTime(mergeDateTime(_fromDate, // _fromTime).getTime()); // LocalDateTime b1 = new LocalDateTime(mergeDateTime(_toDate, // _toTime).getTime()); // LocalDateTime a1 = mergeLocalDateTime(_fromDate, _fromTime); // LocalDateTime b1 = mergeLocalDateTime(_toDate, _toTime); DateTime a1 = mergeDateTime2(_fromDate, _fromTime); DateTime b1 = mergeDateTime2(_toDate, _toTime); // Duration d = new Duration(a, b); Duration d1 = new Duration(a1.toDateTime(DateTimeZone.UTC), b1.toDateTime(DateTimeZone.UTC)); // logger.debug(String.format("%s", duration)); // logger.debug(d.getMillis() / 1000d / 60d / 60d); logger.debug(d1.getMillis() / 1000d / 60d / 60d); duration = d1.getMillis() / 1000d / 60d / 60d; } else { duration = 0d; } } catch (Exception e) { logger.error("calculateDuration", e); duration = 0d; } finally { calFromDate = null; calFromTime = null; calToDate = null; calToTime = null; fromDateTime = null; toDateTime = null; } // setDuration(duration); return duration; }
From source file:monasca.api.infrastructure.persistence.hibernate.AlarmSqlRepoImpl.java
License:Apache License
private List<Alarm> findInternal(String tenantId, String alarmDefId, String metricName, Map<String, String> metricDimensions, AlarmState state, String lifecycleState, String link, DateTime stateUpdatedStart, String offset, int limit, boolean enforceLimit) { Session session = null;//from ww w . ja v a 2s .com List<Alarm> alarms = new LinkedList<>(); try { Query query; session = sessionFactory.openSession(); StringBuilder sbWhere = new StringBuilder("(select a.id " + "from alarm as a, alarm_definition as ad " + "where ad.id = a.alarm_definition_id " + " and ad.deleted_at is null " + " and ad.tenant_id = :tenantId "); if (alarmDefId != null) { sbWhere.append(" and ad.id = :alarmDefId "); } if (metricName != null) { sbWhere.append(" and a.id in (select distinct a.id from alarm as a " + "inner join alarm_metric as am on am.alarm_id = a.id " + "inner join metric_definition_dimensions as mdd " + " on mdd.id = am.metric_definition_dimensions_id " + "inner join (select distinct id from metric_definition " + " where name = :metricName) as md " + " on md.id = mdd.metric_definition_id "); buildJoinClauseFor(metricDimensions, sbWhere); sbWhere.append(")"); } else if (metricDimensions != null) { sbWhere.append(" and a.id in (select distinct a.id from alarm as a " + "inner join alarm_metric as am on am.alarm_id = a.id " + "inner join metric_definition_dimensions as mdd " + " on mdd.id = am.metric_definition_dimensions_id "); buildJoinClauseFor(metricDimensions, sbWhere); sbWhere.append(")"); } if (state != null) { sbWhere.append(" and a.state = :state"); } if (lifecycleState != null) { sbWhere.append(" and a.lifecycle_state = :lifecycleState"); } if (link != null) { sbWhere.append(" and a.link = :link"); } if (stateUpdatedStart != null) { sbWhere.append(" and a.state_updated_at >= :stateUpdatedStart"); } if (offset != null) { sbWhere.append(" and a.id > :offset"); } sbWhere.append(" order by a.id ASC "); if (enforceLimit && limit > 0) { sbWhere.append(" limit :limit"); } sbWhere.append(")"); String sql = String.format(FIND_ALARMS_SQL, sbWhere); try { query = session.createSQLQuery(sql); } catch (Exception e) { logger.error("Failed to bind query {}, error is {}", sql, e.getMessage()); throw new RuntimeException("Failed to bind query", e); } query.setString("tenantId", tenantId); if (alarmDefId != null) { query.setString("alarmDefId", alarmDefId); } if (offset != null) { query.setString("offset", offset); } if (metricName != null) { query.setString("metricName", metricName); } if (state != null) { query.setString("state", state.name()); } if (link != null) { query.setString("link", link); } if (lifecycleState != null) { query.setString("lifecycleState", lifecycleState); } if (stateUpdatedStart != null) { query.setDate("stateUpdatedStart", stateUpdatedStart.toDateTime(DateTimeZone.UTC).toDate()); } if (enforceLimit && limit > 0) { query.setInteger("limit", limit + 1); } bindDimensionsToQuery(query, metricDimensions); List<Object[]> alarmList = (List<Object[]>) query.list(); alarms = createAlarms(alarmList); } finally { if (session != null) { session.close(); } } return alarms; }