Example usage for org.joda.time DateTimeZone UTC

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

Introduction

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

Prototype

DateTimeZone UTC

To view the source code for org.joda.time DateTimeZone UTC.

Click Source Link

Document

The time zone for Universal Coordinated Time

Usage

From source file:com.helger.datetime.config.PDTConfig.java

License:Apache License

/**
 * @return The default UTC date time zone. Never <code>null</code>.
 *//*  w ww  . j  av  a  2 s  . co m*/
@Nonnull
public static DateTimeZone getDateTimeZoneUTC() {
    return DateTimeZone.UTC;
}

From source file:com.hpcloud.mon.infrastructure.persistence.influxdb.AlarmStateHistoryInfluxDbRepositoryImpl.java

License:Apache License

private List<AlarmStateHistory> queryInfluxDBForAlarmStateHistory(String query) {

    logger.debug("Query string: {}", query);

    List<Serie> result = this.influxDB.Query(this.config.influxDB.getName(), query, TimeUnit.MILLISECONDS);

    List<AlarmStateHistory> alarmStateHistoryList = new LinkedList<>();

    // Should only be one serie -- alarm_state_history.
    for (Serie serie : result) {
        Object[][] valObjArryArry = serie.getPoints();
        for (int i = 0; i < valObjArryArry.length; i++) {

            AlarmStateHistory alarmStateHistory = new AlarmStateHistory();
            // Time is always in position 0.
            Double timeDouble = (Double) valObjArryArry[i][0];
            alarmStateHistory.setTimestamp(new DateTime(timeDouble.longValue(), DateTimeZone.UTC));
            // Sequence_number is always in position 1.
            alarmStateHistory.setAlarmId((String) valObjArryArry[i][2]);
            alarmStateHistory.setNewState(AlarmState.valueOf((String) valObjArryArry[i][3]));
            alarmStateHistory.setOldState(AlarmState.valueOf((String) valObjArryArry[i][4]));
            alarmStateHistory.setReason((String) valObjArryArry[i][5]);
            alarmStateHistory.setReasonData((String) valObjArryArry[i][6]);

            alarmStateHistoryList.add(alarmStateHistory);
        }/*from   w w  w  .  j  a  v  a 2 s .  c om*/
    }

    return alarmStateHistoryList;
}

From source file:com.hpcloud.persistence.BeanMapper.java

License:Apache License

@SuppressWarnings({ "rawtypes", "unchecked" })
public T map(int row, ResultSet rs, StatementContext ctx) throws SQLException {
    T bean;//from   w  ww  . ja va  2s  .co m
    try {
        bean = type.newInstance();
    } catch (Exception e) {
        throw new IllegalArgumentException(
                String.format("A bean, %s, was mapped " + "which was not instantiable", type.getName()), e);
    }

    ResultSetMetaData metadata = rs.getMetaData();

    for (int i = 1; i <= metadata.getColumnCount(); ++i) {
        String name = pascalCaseToCamelCase(metadata.getColumnLabel(i).toLowerCase());
        PropertyDescriptor descriptor = properties.get(name);

        if (descriptor != null) {
            Class<?> type = descriptor.getPropertyType();

            Object value;

            if (type.isAssignableFrom(Boolean.class) || type.isAssignableFrom(boolean.class)) {
                value = rs.getBoolean(i);
            } else if (type.isAssignableFrom(Byte.class) || type.isAssignableFrom(byte.class)) {
                value = rs.getByte(i);
            } else if (type.isAssignableFrom(Short.class) || type.isAssignableFrom(short.class)) {
                value = rs.getShort(i);
            } else if (type.isAssignableFrom(Integer.class) || type.isAssignableFrom(int.class)) {
                value = rs.getInt(i);
            } else if (type.isAssignableFrom(Long.class) || type.isAssignableFrom(long.class)) {
                if (metadata.getColumnType(i) == Types.TIMESTAMP)
                    value = rs.getTimestamp(i).getTime();
                else
                    value = rs.getLong(i);
            } else if (type.isAssignableFrom(Float.class) || type.isAssignableFrom(float.class)) {
                value = rs.getFloat(i);
            } else if (type.isAssignableFrom(Double.class) || type.isAssignableFrom(double.class)) {
                value = rs.getDouble(i);
            } else if (type.isAssignableFrom(BigDecimal.class)) {
                value = rs.getBigDecimal(i);
            } else if (type.isAssignableFrom(Timestamp.class)) {
                value = rs.getTimestamp(i);
            } else if (type.isAssignableFrom(Time.class)) {
                value = rs.getTime(i);
            } else if (type.isAssignableFrom(Date.class)) {
                value = rs.getDate(i);
            } else if (type.isAssignableFrom(DateTime.class)) {
                Timestamp ts = rs.getTimestamp(i);
                value = ts == null ? null : new DateTime(ts.getTime(), DateTimeZone.UTC);
            } else if (type.isAssignableFrom(String.class)) {
                if (metadata.getColumnType(i) == Types.TIMESTAMP)
                    value = DATETIME_FORMATTER.print(rs.getTimestamp(i).getTime());
                else
                    value = rs.getString(i);
            } else {
                value = rs.getObject(i);
            }

            if (rs.wasNull() && !type.isPrimitive()) {
                value = null;
            }

            if (type.isEnum() && value != null) {
                value = Enum.valueOf((Class) type, (String) value);
            }

            try {
                descriptor.getWriteMethod().invoke(bean, value);
            } catch (IllegalAccessException e) {
                throw new IllegalArgumentException(
                        String.format("Unable to access setter for " + "property, %s", name), e);
            } catch (InvocationTargetException e) {
                throw new IllegalArgumentException(String.format(
                        "Invocation target exception trying to " + "invoker setter for the %s property", name),
                        e);
            } catch (NullPointerException e) {
                throw new IllegalArgumentException(
                        String.format("No appropriate method to " + "write value %s ", value.toString()), e);
            }
        }
    }

    return bean;
}

From source file:com.hurence.logisland.processor.TimeSeriesCsvLoader.java

License:Apache License

/**
 * CSV reader that waits for a 2 columns csv files with or without a header.
 * If less than 2 columns ==> exception, otherwise, the 3rd and following columns are ignored
 *
 * @param in/* www .  j  a  v  a2  s  .  c om*/
 * @param hasHeader
 * @param inputDatetimeFormat input date format
 * @return
 * @throws IOException
 * @throws IllegalArgumentException
 * @throws ArrayIndexOutOfBoundsException
 */
public static List<Record> load(Reader in, boolean hasHeader, DateTimeFormatter inputDatetimeFormat)
        throws IOException {

    List<Record> records = new ArrayList<>();
    for (CSVRecord record : CSVFormat.DEFAULT.parse(in)) {
        try {
            if (!hasHeader) {
                StandardRecord event = new StandardRecord("sensors");
                event.setField(TIMESTAMP_KEY, FieldType.LONG, inputDatetimeFormat.withZone(DateTimeZone.UTC)
                        .parseDateTime(record.get(0)).getMillis());
                event.setField(VALUE_KEY, FieldType.DOUBLE, Double.parseDouble(record.get(1)));

                records.add(event);
            } else {
                TIMESTAMP_KEY = record.get(0);
                VALUE_KEY = record.get(1);
            }

            hasHeader = false;
        } catch (Exception e) {
            logger.error("Parsing error " + e.getMessage());
            throw new RuntimeException("parsing error", e);
        }
    }

    return records;
}

From source file:com.identityconcepts.shibboleth.profile.WSFedHandler.java

License:Apache License

/**
  * Creates an authentication statement for the current request.
  * /*from ww  w.j  a v  a  2 s  .  c  o m*/
  * @param requestContext current request context
  * 
  * @return constructed authentication statement
  */
protected AuthnStatement buildAuthnStatement(WSFedRequestContext requestContext) {

    AuthnContext authnContext = buildAuthnContext(requestContext);

    AuthnStatement statement = authnStatementBuilder.buildObject();
    statement.setAuthnContext(authnContext);
    statement.setAuthnInstant(new DateTime());

    Session session = getUserSession(requestContext.getInboundMessageTransport());
    if (session != null) {
        statement.setSessionIndex(session.getSessionID());
    }

    long maxSPSessionLifetime = requestContext.getProfileConfiguration().getMaximumSPSessionLifetime();
    if (maxSPSessionLifetime > 0) {
        DateTime lifetime = new DateTime(DateTimeZone.UTC).plus(maxSPSessionLifetime);
        log.debug("Explicitly setting SP session expiration time to '{}'", lifetime.toString());
        statement.setSessionNotOnOrAfter(lifetime);
    }

    statement.setSubjectLocality(buildSubjectLocality(requestContext));

    return statement;
}

From source file:com.intuit.wasabi.analytics.impl.Rollup.java

License:Apache License

DateMidnight today() {
    return new DateMidnight(DateTimeZone.UTC);
}

From source file:com.ivona.services.tts.IvonaSpeechCloudClient.java

License:Open Source License

private <Y> Request<Y> prepareRequest(Request<Y> request, ExecutionContext executionContext,
        boolean signRequest) {
    request.setEndpoint(endpoint);//  w w  w.j  a  v a  2s .  c om
    request.setTimeOffset(timeOffset);

    AWSCredentials credentials = awsCredentialsProvider.getCredentials();

    AmazonWebServiceRequest originalRequest = request.getOriginalRequest();
    if (originalRequest != null && originalRequest.getRequestCredentials() != null) {
        credentials = originalRequest.getRequestCredentials();
    }
    if (signRequest) {
        // expiration date is not currently supported on service side, but presignRequest method requires
        // this argument so one with default value is provided.
        Date expirationDate = DateTime.now(DateTimeZone.UTC).plusMinutes(DEFAULT_GET_REQUEST_EXPIRATION_MINUTES)
                .toDate();
        signer.presignRequest(request, credentials, expirationDate);
    } else {
        executionContext.setSigner(signer);
        executionContext.setCredentials(credentials);
    }
    return request;
}

From source file:com.karthikb351.vitinfo2.fragment.schedule.ScheduleListAdapter.java

License:Open Source License

private void compareTimeAndUpdate(ScheduleView scheduleView, String startTime, String endTime) {

    // Formatting strings to get the nearest hours
    startTime = formatTime(startTime);//  ww  w  .  j a v  a 2s  . c  o  m
    endTime = formatTime(endTime);

    // Comparing time
    LocalTime nowTime = LocalTime.now(DateTimeZone.UTC);
    LocalTime floorTime = new LocalTime(startTime);
    LocalTime ceilTime = new LocalTime(endTime);

    // To correct the timezone difference
    nowTime = nowTime.plusHours(5);
    nowTime = nowTime.plusMinutes(30);

    boolean lowerCheck = nowTime.isAfter(floorTime) || nowTime.isEqual(floorTime);
    boolean upperCheck = nowTime.isBefore(ceilTime);
    boolean upperOverCheck = nowTime.isAfter(ceilTime) || nowTime.isEqual(ceilTime);

    if (lowerCheck && upperCheck) {
        scheduleView.setState(TimeLineView.STATE_CURRENT);
    } else if (lowerCheck && upperOverCheck) {
        scheduleView.setState(TimeLineView.STATE_FINISHED);
    } else {
        scheduleView.setState(TimeLineView.STATE_SCHEDULED);
    }
}

From source file:com.knewton.mapreduce.example.StudentEventAbstractMapper.java

License:Apache License

/**
 * Checks to see if the event is in the desired time range.
 *
 * @return True if the event is in the configured time interval
 *//*from w ww .j  a  v a2 s .c o  m*/
private boolean isInTimeRange(long eventId, Context context) {
    DateTime eventTime = new DateTime(eventId, DateTimeZone.UTC);
    // Skip events outside of the desired time range.
    if (timeRange != null && !timeRange.contains(eventTime)) {
        context.getCounter(CounterConstants.STUDENT_EVENTS_JOB, CounterConstants.STUDENT_EVENTS_SKIPPED)
                .increment(1);
        return false;
    }
    return true;
}

From source file:com.knewton.mapreduce.example.StudentEventAbstractMapper.java

License:Apache License

/**
 * Sets up a DateTime interval for excluding student events. When start time is not set then it
 * defaults to the beginning of time. If end date is not specified then it defaults to
 * "the end of time"./*from w ww .  ja v a2 s  .co m*/
 */
private void setupTimeRange(Configuration conf) {
    DateTimeFormatter dtf = DateTimeFormat.forPattern(DATE_TIME_STRING_FORMAT).withZoneUTC();
    String startDateStr = conf.get(PropertyConstants.START_DATE.txt);
    String endDateStr = conf.get(PropertyConstants.END_DATE.txt);
    // No need to instantiate timeRange.
    if (startDateStr == null && endDateStr == null) {
        return;
    }
    DateTime startDate;
    if (startDateStr != null) {
        startDate = dtf.parseDateTime(startDateStr);
    } else {
        startDate = new DateTime(0).year().withMinimumValue().withZone(DateTimeZone.UTC);
    }
    DateTime endDate;
    if (endDateStr != null) {
        endDate = dtf.parseDateTime(endDateStr);
    } else {
        endDate = new DateTime(0).withZone(DateTimeZone.UTC).year().withMaximumValue();
    }
    this.timeRange = new Interval(startDate, endDate);
}