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.fusesource.examples.horo.rssReader.HoroscopeBuilder.java

License:Apache License

public Horoscope build(@Header("sign") StarSign starSign, @Header("date") String date,
        @Header("feedName") String feedName, @Body String entry) throws ParseException {
    Validate.notNull(starSign, "starSign is null");
    Validate.notEmpty(date, "date is empty");
    Validate.notEmpty(feedName, "feedName is empty");
    Validate.notEmpty(entry, "entry is empty");

    Feed feed = new Feed();
    feed.setName(feedName);//from   w w  w  .  j  a v  a  2  s .c  om

    Horoscope horoscope = new Horoscope();
    horoscope.setStarSign(starSign);
    horoscope.setFeed(feed);
    horoscope.setEntry(entry);

    SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
    DateTime dateTime = new DateTime(format.parse(date)).toDateTime(DateTimeZone.UTC).toDateMidnight()
            .toDateTime();
    horoscope.setPredictsFor(dateTime);
    return horoscope;
}

From source file:com.fusesource.examples.horo.web.HoroscopeTranslator.java

License:Apache License

public HoroscopesResponseVO toHoroscopesResponseVO(List<Horoscope> horoscopes) {
    HoroscopesResponseVO responseVO = new HoroscopesResponseVO();
    List<HoroscopeVO> horoscopeVOs = new ArrayList<HoroscopeVO>();
    responseVO.setHoroscopes(horoscopeVOs);
    if (horoscopes != null) {
        for (Horoscope horoscope : horoscopes) {
            HoroscopeVO horoscopeVO = new HoroscopeVO();
            horoscopeVO.setHoroscopeId(horoscope.getId());
            horoscopeVO.setEntry(horoscope.getEntry());
            horoscopeVO.setDate(horoscope.getPredictsFor().withZone(DateTimeZone.UTC).toDate());
            horoscopeVO.setFeedId(0L); // TODO load feed id into model
            horoscopeVO.setStarSign(horoscope.getStarSign().toString());
            horoscopeVOs.add(horoscopeVO);
        }/*from  www  .  ja va 2 s. c o m*/
    }
    return responseVO;
}

From source file:com.ge.predix.acs.policy.evaluation.cache.AbstractPolicyEvaluationCache.java

License:Apache License

private boolean isCachedRequestInvalid(final List<String> values, final DateTime policyEvalTimestamp) {
    DateTime policyEvalTimestampUTC = policyEvalTimestamp.withZone(DateTimeZone.UTC);

    if (connectorService.isResourceAttributeConnectorConfigured()
            || connectorService.isSubjectAttributeConnectorConfigured()) {
        return haveConnectorCacheIntervalsLapsed(connectorService, policyEvalTimestampUTC);
    } else {//from  w  w  w.  ja v a 2 s.  c  o m
        return havePrivilegeServiceAttributesChanged(values, policyEvalTimestampUTC);
    }
}

From source file:com.ge.predix.acs.policy.evaluation.cache.AbstractPolicyEvaluationCache.java

License:Apache License

boolean havePrivilegeServiceAttributesChanged(final List<String> values,
        final DateTime policyEvalTimestampUTC) {
    for (int i = 0; i < values.size() - 1; i++) {
        if (null == values.get(i)) {
            continue;
        }//from   w  ww  .  jav  a2 s .  c o  m
        DateTime invalidationTimestampUTC;
        try {
            invalidationTimestampUTC = (OBJECT_MAPPER.readValue(values.get(i), DateTime.class))
                    .withZone(DateTimeZone.UTC);
        } catch (IOException e) {
            throw new IllegalStateException("Failed to read timestamp from JSON.", e);
        }

        if (invalidationTimestampUTC.isAfter(policyEvalTimestampUTC)) {
            return true;
        }
    }
    return false;
}

From source file:com.ge.predix.acs.policy.evaluation.cache.AbstractPolicyEvaluationCache.java

License:Apache License

boolean haveConnectorCacheIntervalsLapsed(final AttributeConnectorService localConnectorService,
        final DateTime policyEvalTimestampUTC) {
    DateTime nowUTC = new DateTime().withZone(DateTimeZone.UTC);

    int decisionAgeMinutes = Minutes.minutesBetween(policyEvalTimestampUTC, nowUTC).getMinutes();

    boolean hasResourceConnectorIntervalLapsed = localConnectorService.isResourceAttributeConnectorConfigured()
            && decisionAgeMinutes >= localConnectorService.getResourceAttributeConnector()
                    .getMaxCachedIntervalMinutes();

    boolean hasSubjectConnectorIntervalLapsed = localConnectorService.isSubjectAttributeConnectorConfigured()
            && decisionAgeMinutes >= localConnectorService.getSubjectAttributeConnector()
                    .getMaxCachedIntervalMinutes();

    return hasResourceConnectorIntervalLapsed || hasSubjectConnectorIntervalLapsed;
}

From source file:com.getusroi.wms20.parcel.parcelservice.stamps.service.StampsRateServiceBuilder.java

/**
 * this is to get the currentDate in string format to process the current
 * date in Stamps append//www . j  a  v  a 2s . c o  m
 * 
 * @return string form of date ~(YYYY-MM-DD)
 */
private static String getCurrentDateString() {

    org.joda.time.DateTime dateTime_Utc = new DateTime(DateTimeZone.UTC);
    int monthUTC = dateTime_Utc.getMonthOfYear();
    String month;
    switch (monthUTC) {
    case 1:
        month = "01";
        break;
    case 2:
        month = "02";
        break;
    case 3:
        month = "03";
        break;
    case 4:
        month = "04";
        break;
    case 5:
        month = "05";
        break;
    case 6:
        month = "06";
        break;
    case 7:
        month = "07";
        break;
    case 8:
        month = "08";
        break;
    case 9:
        month = "09";
        break;
    default:
        month = Integer.toString(monthUTC);
        break;
    }
    String dateToString = dateTime_Utc.getYear() + "-" + month + "-" + dateTime_Utc.getDayOfMonth();
    return dateToString;
}

From source file:com.github.autermann.matlab.value.MatlabDateTime.java

License:Open Source License

public double[] toArray() {
    DateTime utc = time.toDateTime(DateTimeZone.UTC);
    return new double[] { (double) utc.getYear(), (double) utc.getMonthOfYear(), (double) utc.getDayOfMonth(),
            (double) utc.getHourOfDay(), (double) utc.getMinuteOfHour(),
            (double) utc.getSecondOfMinute() + (double) utc.getMillisOfSecond() / 1000, };

}

From source file:com.github.blacklocus.rdsecho.EchoNew.java

License:Open Source License

@Override
public Boolean call() throws Exception {

    // Do some sanity checks to make sure we aren't generating a bunch of trouble in RDS

    String tagEchoManaged = echo.getTagEchoManaged();

    LOG.info("Checking to see if current echo-created instance (tagged {}) was created less than 24 hours ago. "
            + "If so this operation will not continue.", tagEchoManaged);
    Optional<DBInstance> newestInstanceOpt = echo.lastEchoInstance();
    if (newestInstanceOpt.isPresent()) {

        if (new DateTime(newestInstanceOpt.get().getInstanceCreateTime()).plusHours(24)
                .isAfter(DateTime.now())) {
            LOG.info("  Last echo-created RDS instance {} was created less than 24 hours ago. Aborting.",
                    tagEchoManaged);//from   w  ww .  j ava  2 s .c  om
            return false;

        } else {
            LOG.info("  Last echo-created RDS instance {} was created more than 24 hours ago. Proceeding.",
                    tagEchoManaged);
        }

    } else {
        LOG.info("  No prior echo-created instance found with tag {}. Proceeding.", tagEchoManaged);
    }

    // Locate a suitable snapshot to be the basis of the new instance

    LOG.info("Locating latest snapshot from {}", cfg.snapshotDbInstanceIdentifier());
    Optional<DBSnapshot> dbSnapshotOpt = echo.latestSnapshot();
    if (dbSnapshotOpt.isPresent()) {
        DBSnapshot snapshot = dbSnapshotOpt.get();
        LOG.info("  Located snapshot {} completed on {}", snapshot.getDBSnapshotIdentifier(),
                new DateTime(snapshot.getSnapshotCreateTime()).toDateTimeISO().toString());

    } else {
        LOG.info("  Could not locate a suitable snapshot. Cannot continue.");
        return false;
    }

    // Info summary

    String dbSnapshotIdentifier = dbSnapshotOpt.get().getDBSnapshotIdentifier();
    String newDbInstanceIdentifier = cfg.name() + '-' + DateTime.now(DateTimeZone.UTC).toString("yyyy-MM-dd");
    LOG.info(
            "Proposed new db instance...\n" + "  engine           : {}\n" + "  license model    : {}\n"
                    + "  db instance class: {}\n" + "  multi az         : {}\n" + "  storage type     : {}\n"
                    + "  iops             : {}\n" + "  db snapshot id   : {}\n" + "  db instance id   : {}\n"
                    + "  port             : {}\n" + "  option group name: {}\n" + "  auto minor ver up: {}",
            cfg.newEngine(), cfg.newLicenseModel(), cfg.newDbInstanceClass(), cfg.newMultiAz(),
            cfg.newStorageType(), cfg.newIops(), dbSnapshotIdentifier, newDbInstanceIdentifier, cfg.newPort(),
            cfg.newOptionGroupName(), cfg.newAutoMinorVersionUpgrade());

    // Interactive user confirmation

    if (cfg.interactive()) {
        String format = "Proceed to create a new DB instance from this snapshot? Input %s to confirm.";
        if (!EchoUtil.prompt(newDbInstanceIdentifier, format, newDbInstanceIdentifier)) {
            LOG.info("User declined to proceed. Exiting.");
            return false;
        }
    }

    // Create the new database

    LOG.info("Creating new DB instance. Hold on to your butts.");
    RestoreDBInstanceFromDBSnapshotRequest request = new RestoreDBInstanceFromDBSnapshotRequest()
            .withEngine(cfg.newEngine()).withLicenseModel(cfg.newLicenseModel())
            .withDBInstanceClass(cfg.newDbInstanceClass()).withMultiAZ(cfg.newMultiAz())
            .withStorageType(cfg.newStorageType()).withIops(cfg.newIops())
            .withDBSnapshotIdentifier(dbSnapshotIdentifier).withDBInstanceIdentifier(newDbInstanceIdentifier)
            .withPort(cfg.newPort()).withOptionGroupName(cfg.newOptionGroupName())
            .withAutoMinorVersionUpgrade(cfg.newAutoMinorVersionUpgrade())
            .withTags(new Tag().withKey(echo.getTagEchoManaged()).withValue("true"),
                    new Tag().withKey(echo.getTagEchoStage()).withValue(EchoConst.STAGE_NEW));
    DBInstance restoredInstance = rds.restoreDBInstanceFromDBSnapshot(request);

    Optional<String[]> newTags = cfg.newTags();
    if (newTags.isPresent()) {
        List<Tag> tags = EchoUtil.parseTags(newTags.get());
        if (tags.size() > 0) {
            LOG.info("Applying tags on create new: {}", Arrays.asList(tags));
            AddTagsToResourceRequest tagsRequest = new AddTagsToResourceRequest()
                    .withResourceName(RdsFind.instanceArn(cfg.region(), cfg.accountNumber(),
                            restoredInstance.getDBInstanceIdentifier()));
            tagsRequest.setTags(tags);
            rds.addTagsToResource(tagsRequest);
        }
    }

    LOG.info("Created new DB instance. \n"
            + "  https://console.aws.amazon.com/rds/home?region={}#dbinstance:id={}\n"
            + "Additional preparation of the instance will continue once the instance becomes available.",
            cfg.region(), newDbInstanceIdentifier);

    return true;
}

From source file:com.github.restdriver.serverdriver.matchers.Rfc1123DateMatcher.java

License:Apache License

/**
 * Parse a string as if it is an RFC1123-compliant date.
 * /*from  ww  w.j a  v  a  2 s .  c om*/
 * @param rawString The original String.
 * @return The DateTime object set to UTC.
 */
public DateTime getDateTime(String rawString) {
    SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT, Locale.US);
    formatter.setLenient(false); // This stops well-formatted but invalid dates like Feb 31

    try {
        return new DateTime(formatter.parse(rawString)).toDateTime(DateTimeZone.UTC);

    } catch (ParseException pe) {
        throw new RuntimeDateFormatException(pe);
    }

}

From source file:com.github.terma.gigaspacewebconsole.provider.executor.gigaspace.TimestampPreprocessor.java

License:Apache License

@Override
public String preprocess(String sql) {
    if (sql == null)
        return null;

    sql = replaceTimestamps(TODAY_PATTERN, new DateTime(DateTimeZone.UTC).withTimeAtStartOfDay(), sql);
    sql = replaceTimestamps(NOW_PATTERN, new DateTime(DateTimeZone.UTC), sql);
    return sql;//from  ww w  . ja  v a2s  . co m
}