Example usage for org.joda.time DateTime toDateTime

List of usage examples for org.joda.time DateTime toDateTime

Introduction

In this page you can find the example usage for org.joda.time DateTime toDateTime.

Prototype

public DateTime toDateTime(Chronology chronology) 

Source Link

Document

Get this object as a DateTime, returning this if possible.

Usage

From source file:com.yahoo.bard.webservice.sql.SqlResultSetProcessor.java

License:Apache License

/**
 * Processes the results from the sql {@link ResultSet} and writes them out as
 * the json format returned for a {@link com.yahoo.bard.webservice.druid.model.query.GroupByQuery}.
 *
 * @return the equivalent json./*from   w  ww.  ja  va2  s  .com*/
 */
public JsonNode buildDruidResponse() {
    Map<String, Function<String, Number>> resultTypeMapper = getAggregationTypeMapper(druidQuery);

    try (TokenBuffer jsonWriter = new TokenBuffer(objectMapper, true)) {

        jsonWriter.writeStartArray();
        for (String[] row : sqlResults) {
            jsonWriter.writeStartObject();

            DateTime timestamp;
            if (AllGranularity.INSTANCE.equals(druidQuery.getGranularity())) {
                timestamp = druidQuery.getIntervals().get(0).getStart();
            } else {
                timestamp = sqlTimeConverter.getIntervalStart(groupByDimensionsCount, row, druidQuery);
            }
            // all druid results are returned in UTC timestamps
            jsonWriter.writeStringField("timestamp", timestamp.toDateTime(DateTimeZone.UTC).toString());

            jsonWriter.writeObjectFieldStart("event");
            processRow(resultTypeMapper, jsonWriter, row);
            jsonWriter.writeEndObject();

            jsonWriter.writeEndObject();
        }
        jsonWriter.writeEndArray();

        return jsonWriter.asParser().readValueAsTree();
    } catch (IOException e) {
        throw new RuntimeException("Failed to write json.", e);
    }

}

From source file:controllers.Api.Statistic.java

License:Open Source License

public static Result getAccess() {
    // Variables/*from   w w  w  .j  a v  a 2  s  .  c o  m*/
    Integer newValue, accessHour, yesterdayHour, index = 0;
    DateTime yesterdayDayTime, accessTime;

    // Yesterday Time Calc
    yesterdayDayTime = (new DateTime()).withZone(DateTimeZone.forID(session("timezone")));
    //yesterdayDayTime = yesterdayDayTime.minusHours(24);
    yesterdayDayTime = yesterdayDayTime.minusHours(23).minusMinutes(yesterdayDayTime.getMinuteOfHour())
            .minusSeconds(yesterdayDayTime.getSecondOfMinute());
    yesterdayHour = yesterdayDayTime.getHourOfDay();

    DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    List<models.Access> accessDay = models.Access.find.where()
            .ge("timestamp", fmt.print(yesterdayDayTime.toDateTime(DateTimeZone.UTC))).order().asc("timestamp")
            .findList();
    Iterator<models.Access> accessDayIterator = accessDay.iterator();

    // 0 Liste initialisieren
    List<Integer> accessDayReturn = Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0);

    // Iterate List
    while (accessDayIterator.hasNext()) {
        models.Access access = accessDayIterator.next();
        // Access Time Calc
        accessTime = access.timestamp;
        accessTime = accessTime.withZone(DateTimeZone.forID(session("timezone")));
        accessHour = accessTime.getHourOfDay();

        // Set value
        if (accessHour == yesterdayHour) {
            index = accessDayReturn.size() - 1;
        } else if (accessHour > yesterdayHour) {
            index = accessHour - yesterdayHour;
        } else if (accessHour < yesterdayHour) {
            index = (24 - (yesterdayHour - accessHour)) % 24;
        }

        newValue = accessDayReturn.get(index) + 1;
        accessDayReturn.set(index, newValue);

    }
    return ok(Json.toJson(accessDayReturn));
}

From source file:de.fu_berlin.inf.dpp.feedback.SessionStatistic.java

License:Open Source License

public void setLocalSessionStartTime(DateTime localSessionStart) {
    data.setProperty(KEY_SESSION_LOCAL_START, localSessionStart.toDateTime(DateTimeZone.UTC).toString());
}

From source file:de.fu_berlin.inf.dpp.feedback.SessionStatistic.java

License:Open Source License

public void setLocalSessionEndTime(DateTime localSessionEnd) {
    data.setProperty(KEY_SESSION_LOCAL_START, localSessionEnd.toDateTime(DateTimeZone.UTC).toString());
}

From source file:divconq.lang.BigDateTime.java

License:Open Source License

/**
 * @param date translates into BigDateTime
 *//*  w  ww.j a v a  2 s  . co  m*/
public BigDateTime(DateTime date) {
    if (date == null)
        return;

    // make sure we are using ISO and UTC
    date = date.toDateTime(ISOChronology.getInstanceUTC());
    //date = date.toDateTime(DateTimeZone.UTC);      

    this.year = 50000000000L + date.getYear(); // ISO says 1 BCE = 0, 2 BCE = -1, etc
    this.month = date.getMonthOfYear();
    this.day = date.getDayOfMonth();
    this.hour = date.getHourOfDay();
    this.minute = date.getMinuteOfHour();
    this.second = date.getSecondOfMinute();
}

From source file:divconq.sql.SqlManager.java

License:Open Source License

public String getDateAsString(DateTime dt) {
    return this.stampFmt.print(dt.toDateTime(DateTimeZone.UTC));
}

From source file:edu.internet2.middleware.shibboleth.common.session.impl.AbstractSession.java

License:Open Source License

/** {@inheritDoc} */
public /*synchronized*/ void setLastActivityInstant(DateTime activity) {
    lastActivity = activity.toDateTime(ISOChronology.getInstanceUTC()).getMillis();
    changed = true;//  w  ww. ja v  a  2s . c  o  m
}

From source file:edu.internet2.middleware.shibboleth.idp.session.AbstractSession.java

License:Open Source License

/** {@inheritDoc} */
public synchronized void setLastActivityInstant(DateTime activity) {
    lastActivity = activity.toDateTime(ISOChronology.getInstanceUTC()).getMillis();

    fireEvent(SessionEventType.CHANGED);
}

From source file:edu.internet2.middleware.shibboleth.idp.session.impl.AuthenticationMethodInformationImpl.java

License:Open Source License

/**
 * Default constructor.  This constructor does NOT add the given principal to the given subject.
 * //from   w  ww . j  av a 2  s .  co m
 * @param subject subject associated with the user's session
 * @param principal principal created by the authentication method
 * @param method The unique identifier for the authentication method
 * @param instant The time the user authenticated with this member
 * @param duration The duration of this authentication method
 */
public AuthenticationMethodInformationImpl(Subject subject, Principal principal, String method,
        DateTime instant, long duration) {

    if (method == null || instant == null || duration < 0) {
        throw new IllegalArgumentException("Authentication method, instant, and duration may not be null");
    }

    authenticationSubject = subject;
    authenticationPrincipal = principal;
    authenticationMethod = method;
    authenticationInstant = instant.toDateTime(ISOChronology.getInstanceUTC()).getMillis();
    authenticationDuration = duration;
    expirationInstant = authenticationInstant + duration;
}

From source file:edu.internet2.middleware.shibboleth.idp.session.impl.ServiceInformationImpl.java

License:Open Source License

/**
 * Default constructor./*from   w  w w. ja va 2 s  .c  o m*/
 * 
 * @param id unique identifier for the service.
 * @param loginInstant time the user logged in to the service.
 * @param method authentication method used to log into the service.
 */
public ServiceInformationImpl(String id, DateTime loginInstant, AuthenticationMethodInformation method) {
    entityID = id;
    authenticationInstant = loginInstant.toDateTime(ISOChronology.getInstanceUTC()).getMillis();
    methodInfo = method;
}