Example usage for org.joda.time DateTimeZone getID

List of usage examples for org.joda.time DateTimeZone getID

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone getID.

Prototype

@ToString
public final String getID() 

Source Link

Document

Gets the ID of this datetime zone.

Usage

From source file:org.apache.druid.sql.calcite.expression.builtin.TimeShiftOperatorConversion.java

License:Apache License

@Override
public DruidExpression toDruidExpression(final PlannerContext plannerContext, final RowSignature rowSignature,
        final RexNode rexNode) {
    final RexCall call = (RexCall) rexNode;
    final DruidExpression timeExpression = Expressions.toDruidExpression(plannerContext, rowSignature,
            call.getOperands().get(0));/* w ww.  ja  va  2 s. co m*/

    final DruidExpression periodExpression = Expressions.toDruidExpression(plannerContext, rowSignature,
            call.getOperands().get(1));

    final DruidExpression stepExpression = Expressions.toDruidExpression(plannerContext, rowSignature,
            call.getOperands().get(2));

    if (timeExpression == null || periodExpression == null || stepExpression == null) {
        return null;
    }

    final DateTimeZone timeZone = OperatorConversions.getOperandWithDefault(call.getOperands(), 3,
            operand -> DateTimes.inferTzFromString(RexLiteral.stringValue(operand)),
            plannerContext.getTimeZone());

    return DruidExpression.fromFunctionCall("timestamp_shift",
            ImmutableList
                    .of(timeExpression.getExpression(), periodExpression.getExpression(),
                            stepExpression.getExpression(), DruidExpression.stringLiteral(timeZone.getID()))
                    .stream().map(DruidExpression::fromExpression).collect(Collectors.toList()));
}

From source file:org.codelibs.elasticsearch.common.io.stream.StreamOutput.java

License:Apache License

/**
 * Write a {@linkplain DateTimeZone} to the stream.
 *///  w  ww . ja va2 s.  c  om
public void writeTimeZone(DateTimeZone timeZone) throws IOException {
    writeString(timeZone.getID());
}

From source file:org.gephi.graph.impl.Serialization.java

License:Apache License

private void serializeTimeZone(final DataOutput out, final DateTimeZone timeZone) throws IOException {
    serialize(out, timeZone.getID());
}

From source file:org.graylog2.restclient.models.api.requests.CreateUserRequest.java

License:Open Source License

public CreateUserRequest(User user) {
    this.username = user.getName();
    this.fullname = user.getFullName();
    this.email = user.getEmail();
    this.password = "";
    this.permissions = user.getPermissions();
    final DateTimeZone timeZone = user.getTimeZone();
    if (timezone != null) {
        this.timezone = timeZone.getID();
    }//from w w w .j a v  a2 s . c o m
    this.sessionTimeoutMs = user.getSessionTimeoutMs();
}

From source file:org.graylog2.users.UserImpl.java

License:Open Source License

@Override
public void setTimeZone(final DateTimeZone timeZone) {
    fields.put(TIMEZONE, timeZone.getID());
}

From source file:org.jasig.portlet.calendar.adapter.CalendarEventsDao.java

License:Apache License

/**
 * Obtains the calendar events from the adapter and returns timezone-adjusted
 * events within the requested interval.
 * @param adapter Adapter to invoke to obtain the calendar events
 * @param calendar Per-user Calendar configuration
 * @param interval Interval to return events for
 * @param request Portlet request// www. j  a v a2  s  . c o  m
 * @param usersConfiguredDateTimeZone Timezone to adjust the calendar events to (typically the user's timezone)
 * @return Set of calendar events meeting the requested criteria
 */
public Set<CalendarDisplayEvent> getEvents(ICalendarAdapter adapter, CalendarConfiguration calendar,
        Interval interval, PortletRequest request, DateTimeZone usersConfiguredDateTimeZone) {

    // Get the set of calendar events for the requested period.
    // We invoke the adapter before checking cache because we expect the adapter
    // to do the first-level caching of the events.
    final CalendarEventSet eventSet = adapter.getEvents(calendar, interval, request);

    // The calendar events from the adapter will reflect the timezone of the calendar
    // server in the event times.  The events need to be corrected to reflect the
    // requested timezone (typically the user's timezone). Adjusting the
    // event's timezone is an expensive operation so the JSON of the
    // timezone-adjusted events is cached per timezone.

    // Append the requested time zone id to the retrieve event set's cache
    // key to generate a timezone-aware cache key
    final String tzKey = eventSet.getKey().concat(usersConfiguredDateTimeZone.getID());

    // attempt to retrieve the timezone-aware event set from cache
    Element cachedElement = this.cache.get(tzKey);
    if (cachedElement != null) {
        if (log.isDebugEnabled()) {
            log.debug("Retrieving JSON timezone-aware event set from cache, key:" + tzKey);
        }
        @SuppressWarnings("unchecked")
        final Set<CalendarDisplayEvent> jsonEvents = (Set<CalendarDisplayEvent>) cachedElement.getValue();
        return jsonEvents;
    }

    // if the timezone-corrected event set is not available in the cache
    // generate a new set and cache it
    else {

        // for each event in the event set, generate a set of timezone-corrected
        // event occurrences and add it to the new set
        final Set<CalendarDisplayEvent> displayEvents = new HashSet<CalendarDisplayEvent>();
        for (VEvent event : eventSet.getEvents()) {
            try {
                displayEvents.addAll(
                        getDisplayEvents(event, interval, request.getLocale(), usersConfiguredDateTimeZone));
            } catch (ParseException e) {
                log.error("Exception parsing event", e);
            } catch (IOException e) {
                log.error("Exception parsing event", e);
            } catch (URISyntaxException e) {
                log.error("Exception parsing event", e);
            } catch (IllegalArgumentException e) {
                // todo fix the root problem. Just masking for the moment because no time to fix.
                log.info("Likely invalid event returned from exchangeAdapter; see CAP-159");
            }
        }

        // Cache and return the resulting event list.  If the event set
        // was cached, set the event list to expire at about the same time so it
        // doesn't live in cache beyond the time the data it is derived
        // from is considered up to date. Time to live is relative to the
        // time the item is put into cache so the resulting event list will typically
        // expire from 1 second before the event set to afterward by the amount
        // of execution time from the adapter to displayEvents computation
        // completing which should not be a big delta.
        cachedElement = new Element(tzKey, displayEvents);
        long currentTime = System.currentTimeMillis();
        if (eventSet.getExpirationTime() > currentTime) {
            long timeToLiveInMilliseconds = eventSet.getExpirationTime() - currentTime;
            int timeToLiveInSeconds = (int) timeToLiveInMilliseconds / 1000;
            cachedElement.setTimeToLive(timeToLiveInSeconds);
            if (log.isDebugEnabled()) {
                log.debug("Storing JSON timezone-aware event set to cache, key:" + tzKey
                        + " with expiration in " + timeToLiveInSeconds + " seconds to"
                        + " coincide with adapter's cache expiration time");
            }
        }
        this.cache.put(cachedElement);
        return displayEvents;
    }

}

From source file:org.jasig.portlet.calendar.adapter.CalendarEventsDao.java

License:Apache License

protected DateTimeFormatter getDateFormatter(Locale locale, DateTimeZone timezone) {
    if (this.dateFormatters.containsKey(timezone.getID())) {
        return this.dateFormatters.get(timezone.getID());
    }/* w  w w  .  j  ava 2 s  .  co  m*/
    final String displayPattern = this.messageSource.getMessage("date.formatter.display", null, "EEE MMM d",
            locale);
    DateTimeFormatter df = new DateTimeFormatterBuilder().appendPattern(displayPattern).toFormatter()
            .withZone(timezone);
    this.dateFormatters.put(timezone.getID(), df);
    return df;
}

From source file:org.jasig.portlet.calendar.adapter.CalendarEventsDao.java

License:Apache License

protected DateTimeFormatter getTimeFormatter(Locale locale, DateTimeZone timezone) {
    if (this.timeFormatters.containsKey(timezone.getID())) {
        return this.timeFormatters.get(timezone.getID());
    }/*w ww.  jav a 2s .  c o  m*/
    final String displayPattern = this.messageSource.getMessage("time.formatter.display", null, "h:mm a",
            locale);
    DateTimeFormatter tf = new DateTimeFormatterBuilder().appendPattern(displayPattern).toFormatter()
            .withZone(timezone);
    this.timeFormatters.put(timezone.getID(), tf);
    return tf;
}

From source file:org.jboss.seam.international.datetimezone.DefaultDateTimeZoneProducer.java

License:Apache License

private ForwardingDateTimeZone constructTimeZone(final DateTimeZone dtz) {
    return new ForwardingDateTimeZone(dtz.getID()) {
        @Override/*from  w  w  w.  j  ava 2  s . com*/
        protected DateTimeZone delegate() {
            return dtz;
        }
    };
}

From source file:org.ohmage.query.impl.AnnotationQueries.java

License:Apache License

@Override
public void createSurveyResponseAnnotation(final UUID annotationId, final String client, final Long time,
        final DateTimeZone timezone, final String annotationText, final UUID surveyId)
        throws DataAccessException {

    // Create the transaction.
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("Creating a new survey response annotation.");

    try {//from  ww  w .ja v  a  2 s .  c  o  m
        // Begin the transaction.
        PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource());
        TransactionStatus status = transactionManager.getTransaction(def);
        long id = 0;

        try {
            id = insertAnnotation(annotationId, time, timezone, client, annotationText);
        } catch (org.springframework.dao.DataAccessException e) {

            transactionManager.rollback(status);
            throw new DataAccessException("Error while executing SQL '" + SQL_INSERT_ANNOTATION
                    + "' with parameters: " + annotationId + ", " + time + ", " + timezone.getID() + ", "
                    + client + ", " + ((annotationText.length() > 25) ? annotationText.substring(0, 25) + "..."
                            : annotationText),
                    e);
        }

        try {
            // Insert the link between the survey_response and its annotation
            getJdbcTemplate().update(SQL_INSERT_SURVEY_RESPONSE_ANNOTATION, surveyId.toString(), id);

        } catch (org.springframework.dao.DataAccessException e) {

            transactionManager.rollback(status);
            throw new DataAccessException("Error while executing SQL '" + SQL_INSERT_SURVEY_RESPONSE_ANNOTATION
                    + "' with parameters: " + surveyId.toString() + ", " + id, e);
        }

        // Commit the transaction.
        try {
            transactionManager.commit(status);
        } catch (TransactionException e) {
            transactionManager.rollback(status);
            throw new DataAccessException("Error while committing the transaction.", e);
        }

    } catch (TransactionException e) {
        throw new DataAccessException("Error while attempting to rollback the transaction.", e);
    }
}