Example usage for org.joda.time DateTimeZone forID

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

Introduction

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

Prototype

@FromString
public static DateTimeZone forID(String id) 

Source Link

Document

Gets a time zone instance for the specified time zone id.

Usage

From source file:cmg.org.monitor.services.GoogleAccountService.java

License:Open Source License

/**
 * Gets the timestamp string.//from ww w.  ja  v  a  2  s  . com
 *
 * @return the timestamp string
 */
private String getTimestampString() {
    DateTime t = new DateTime(new Date(System.currentTimeMillis()));
    t = t.withZone(DateTimeZone.forID(currentZone));
    return t.toString(DateTimeFormat.forPattern("dd/MM/yyyy hh:mm:ss.SSS"));
}

From source file:com.addthis.hydra.data.util.TimeField.java

License:Apache License

@Override
public void postDecode() {
    if (format.equals("native")) {
        format = "unixmillis:10";
    }/*from  w w w.  j  a va  2s.  co m*/
    if (format.startsWith("unixmillis")) {
        if (format.indexOf(":") > 0) {
            radix = Integer.parseInt(format.substring(format.indexOf(":") + 1));
        } else {
            radix = 10;
        }
    } else {
        formatter = DateTimeFormat.forPattern(format);
        if (timeZone != null) {
            formatter = formatter.withZone(DateTimeZone.forID(timeZone));
        }
    }
}

From source file:com.addthis.hydra.task.output.tree.PathPrune.java

License:Apache License

@JsonCreator
public PathPrune(@Time(TimeUnit.MILLISECONDS) @JsonProperty("ttl") long ttl,
        @Nullable @JsonProperty("nameFormat") String nameFormat,
        @Nullable @JsonProperty("timezone") String timezone,
        @Nullable @JsonProperty("treePath") String treePath, @JsonProperty("timePropKey") String timePropKey,
        @JsonProperty("ignoreMissingTimeProp") boolean ignoreMissingTimeProp,
        @JsonProperty("allLeaves") boolean allLeaves, @JsonProperty("relativeDown") int relativeDown,
        @JsonProperty("preempt") boolean preempt, @JsonProperty("excludes") ImmutableSet<String> excludes) {
    this.ttl = ttl;
    this.timePropKey = timePropKey;
    this.ignoreMissingTimeProp = ignoreMissingTimeProp;
    this.allLeaves = allLeaves;
    this.relativeDown = relativeDown;
    this.preempt = preempt;
    this.excludes = excludes;
    if (nameFormat != null && timezone != null) {
        this.nameFormat = DateTimeFormat.forPattern(nameFormat).withZone(DateTimeZone.forID(timezone));
    } else if (nameFormat != null) {
        this.nameFormat = DateTimeFormat.forPattern(nameFormat);
    } else {/*  w w w .  ja v a2 s.  c  om*/
        this.nameFormat = null;
    }
    if ((treePath != null) && (relativeDown != 0)) {
        throw new IllegalStateException("cannot use both treePath and relativeDown parameters");
    }
    if (treePath != null) {
        this.treePath = ImmutableList.copyOf(SLASH_SPLITTER.splitToList(treePath));
    } else {
        this.treePath = null;
    }
}

From source file:com.aionemu.gameserver.utils.gametime.DateTimeUtil.java

License:Open Source License

public static void init() {
    try {// w  w w.ja v  a2  s. c o m
        if (!GSConfig.TIME_ZONE_ID.isEmpty()) {
            // just check the validity on start (if invalid zone specified in the switch, default id used)
            DateTimeZone.forID(System.getProperty("Duser.timezone"));
            DateTimeZone.forID(GSConfig.TIME_ZONE_ID);
            canApplyZoneChange = true;
        }
    } catch (Throwable e) {
        log.error("Invalid or not supported timezones specified!!!\n"
                + "Use both -Duser.timezone=\"timezone_id\" switch from command line\n"
                + "and add a valid value for GSConfig.TIME_ZONE_ID");
    }
}

From source file:com.aionemu.gameserver.utils.gametime.DateTimeUtil.java

License:Open Source License

public static DateTime getDateTime() {
    DateTime dt = new DateTime();
    if (canApplyZoneChange) {
        return dt.withZoneRetainFields(DateTimeZone.forID(GSConfig.TIME_ZONE_ID));
    }//  ww w . j ava2 s.  c o m
    return dt;
}

From source file:com.aionemu.gameserver.utils.gametime.DateTimeUtil.java

License:Open Source License

public static DateTime getDateTime(String isoDateTime) {
    DateTime dt = new DateTime(isoDateTime);
    if (canApplyZoneChange) {
        return dt.withZoneRetainFields(DateTimeZone.forID(GSConfig.TIME_ZONE_ID));
    }/*from   w w w. j  av  a 2s . com*/
    return dt;
}

From source file:com.aionemu.gameserver.utils.gametime.DateTimeUtil.java

License:Open Source License

public static DateTime getDateTime(GregorianCalendar calendar) {
    DateTime dt = new DateTime(calendar);
    if (canApplyZoneChange) {
        return dt.withZoneRetainFields(DateTimeZone.forID(GSConfig.TIME_ZONE_ID));
    }//w  w  w. ja  va2 s .com
    return dt;
}

From source file:com.aionemu.gameserver.utils.gametime.DateTimeUtil.java

License:Open Source License

public static DateTime getDateTime(long millisSinceSeventies) {
    DateTime dt = new DateTime(millisSinceSeventies);
    if (canApplyZoneChange) {
        return dt.withZoneRetainFields(DateTimeZone.forID(GSConfig.TIME_ZONE_ID));
    }//from w  w  w.java2  s.  co  m
    return dt;
}

From source file:com.almende.timecontrol.time.TriggerPattern.java

License:Apache License

/**
 * @param measure//from  www . j a v a2s . c  o m
 * @return
 * 
 * @see CronScheduleBuilder#cronSchedule(String)
 * @see DateTimeIteratorFactory#createDateTimeIterable(String,
 *      ReadableDateTime, DateTimeZone, boolean)
 */
public static final Observable<Instant> parseInstantOrIntervalOrRule(final String json) {
    try {
        // example: "0/20 * * * * ?"
        final CronTrigger trigger = TriggerBuilder.newTrigger()
                .withSchedule(CronScheduleBuilder.cronSchedule(json)).build();
        return Observable.create(new Observable.OnSubscribe<Instant>() {
            @Override
            public void call(final Subscriber<? super Instant> sub) {
                Date current = trigger.getStartTime();
                while (current != null) {
                    sub.onNext(Instant.valueOf(current.getTime()));
                    current = trigger.getFireTimeAfter(current);
                }
            }
        });
    } catch (final Exception e) {
        try {
            final boolean strict = false;
            // String ical =
            // "DTSTART;TZID=US-Eastern:19970902T090000\r\n"+"RRULE:FREQ=DAILY;"
            // + "UNTIL=20130430T083000Z;"
            // + "INTERVAL=1;";

            // FIXME parse DTSTART (see
            // http://www.kanzaki.com/docs/ical/rrule.html)
            final DateTimeZone zone = DateTimeZone.forID(dtStartZonePattern.matcher(json).group());
            final DateTime start = DateTime.parse(dtStartTimePattern.matcher(json).group()).withZone(zone);

            // convert DateTime to Instant
            return Observable.from(DateTimeIteratorFactory.createDateTimeIterable(json, start, zone, strict))
                    .map(new Func1<DateTime, Instant>() {
                        @Override
                        public Instant call(final DateTime dt) {
                            return Instant.valueOf(dt);
                        }
                    });
        } catch (final Exception e1) {
            return Observable.just(Instant.valueOf(json));
        }
    }
}

From source file:com.auditbucket.engine.service.TrackService.java

License:Open Source License

/**
 * Event log record for the supplied metaHeader from the supplied input
 *
 * @param authorisedHeader metaHeader the caller is authorised to work with
 * @param input            trackLog details containing the data to log
 * @param thisFortressUser User name in calling system that is making the change
 * @return populated log information with any error messages
 *///from  ww w. j  a  v a  2s.  c  o  m
private LogResultBean createLog(MetaHeader authorisedHeader, LogInputBean input, FortressUser thisFortressUser)
        throws DatagioException {
    // Warning - making this private means it doesn't get a transaction!
    LogResultBean resultBean = new LogResultBean(input);
    //ToDo: May want to track a "View" event which would not change the What data.
    if (input.getMapWhat() == null || input.getMapWhat().isEmpty()) {
        resultBean.setStatus(LogInputBean.LogStatus.IGNORE);
        resultBean.setMessage("No 'what' information provided. Ignoring this request");
        return resultBean;
    }

    Fortress fortress = authorisedHeader.getFortress();

    // Transactions checks
    TxRef txRef = handleTxRef(input, fortress.getCompany());
    resultBean.setTxReference(txRef);

    // https://github.com/monowai/auditbucket/issues/7
    TrackLog existingLog = null;
    if (authorisedHeader.getLastUpdated() != authorisedHeader.getWhenCreated()) // Will there even be a change to find
        existingLog = getLastLog(authorisedHeader);

    Boolean searchActive = fortress.isSearchActive();
    DateTime fortressWhen = (input.getWhen() == null ? new DateTime(DateTimeZone.forID(fortress.getTimeZone()))
            : new DateTime(input.getWhen()));

    if (existingLog != null) {
        try {
            if (whatService.isSame(authorisedHeader, existingLog.getChange(), input.getWhat())) {
                logger.trace("Ignoring a change we already have {}", input);
                input.setStatus(LogInputBean.LogStatus.IGNORE);
                if (input.isForceReindex()) { // Caller is recreating the search index
                    searchFacade.makeChangeSearchable(prepareSearchDocument(authorisedHeader, input,
                            existingLog.getChange().getEvent(), searchActive, fortressWhen, existingLog));
                    resultBean.setMessage("Ignoring a change we already have. Honouring request to re-index");
                } else
                    resultBean.setMessage("Ignoring a change we already have");
                return resultBean;
            }
        } catch (IOException e) {
            input.setStatus(LogInputBean.LogStatus.ILLEGAL_ARGUMENT);
            resultBean.setMessage("Error comparing JSON data: " + e.getMessage());
            logger.error("Error comparing JSON Data", e);
            return resultBean;
        }
        if (input.getEvent() == null) {
            input.setEvent(ChangeLog.UPDATE);
        }
        if (searchActive)
            authorisedHeader = waitOnInitialSearchResult(authorisedHeader);

    } else { // first ever log for the metaHeader
        if (input.getEvent() == null) {
            input.setEvent(ChangeLog.CREATE);
        }
        //if (!metaHeader.getLastUser().getId().equals(thisFortressUser.getId())){
        authorisedHeader.setLastUser(thisFortressUser);
        authorisedHeader = trackDao.save(authorisedHeader);

        //}
    }

    ChangeLog thisChange = trackDao.save(thisFortressUser, input, txRef,
            (existingLog != null ? existingLog.getChange() : null));
    input.setChangeEvent(thisChange.getEvent());

    // ToDo: WhatService call should occur after this function is finished.
    //       change should then be written back to the graph via @ServiceActivator as called
    //       by as yet to be extracted ab-what service
    thisChange = whatService.logWhat(authorisedHeader, thisChange, input.getWhat());

    TrackLog newLog = trackDao.addLog(authorisedHeader, thisChange, fortressWhen, existingLog);
    resultBean.setSysWhen(newLog.getSysWhen());

    boolean moreRecent = (existingLog == null || existingLog.getFortressWhen() <= newLog.getFortressWhen());

    input.setStatus(LogInputBean.LogStatus.OK);

    if (moreRecent) {
        if (!authorisedHeader.getLastUser().getId().equals(thisFortressUser.getId())) {
            authorisedHeader.setLastUser(thisFortressUser);
            trackDao.save(authorisedHeader);
        }

        try {
            resultBean.setSearchChange(prepareSearchDocument(authorisedHeader, input, input.getChangeEvent(),
                    searchActive, fortressWhen, newLog));
        } catch (JsonProcessingException e) {
            resultBean.setMessage("Error processing JSON document");
            resultBean.setStatus(LogInputBean.LogStatus.ILLEGAL_ARGUMENT);
        }
    }

    return resultBean;

}