Example usage for org.joda.time DateTimeZone getDefault

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

Introduction

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

Prototype

public static DateTimeZone getDefault() 

Source Link

Document

Gets the default time zone.

Usage

From source file:org.jruby.CompatVersion.java

License:LGPL

public static DateTimeZone getLocalTimeZone(Ruby runtime) {
        RubyString tzVar = runtime.newString(TZ_STRING);
        RubyHash h = ((RubyHash) runtime.getObject().fastGetConstant("ENV"));
        IRubyObject tz = h.op_aref(runtime.getCurrentContext(), tzVar);
        if (tz == null || !(tz instanceof RubyString)) {
            return DateTimeZone.getDefault();
        } else {/*  ww w .  j  a v a  2 s  . co m*/
            String zone = tz.toString();
            DateTimeZone cachedZone = runtime.getLocalTimezoneCache().get(zone);

            if (cachedZone != null)
                return cachedZone;

            String originalZone = zone;

            // Value of "TZ" property is of a bit different format,
            // which confuses the Java's TimeZone.getTimeZone(id) method,
            // and so, we need to convert it.

            Matcher tzMatcher = TZ_PATTERN.matcher(zone);
            if (tzMatcher.matches()) {
                String sign = tzMatcher.group(2);
                String hours = tzMatcher.group(3);
                String minutes = tzMatcher.group(4);

                // GMT+00:00 --> Etc/GMT, see "MRI behavior"
                // comment below.
                if (("00".equals(hours) || "0".equals(hours))
                        && (minutes == null || ":00".equals(minutes) || ":0".equals(minutes))) {
                    zone = "Etc/GMT";
                } else {
                    // Invert the sign, since TZ format and Java format
                    // use opposite signs, sigh... Also, Java API requires
                    // the sign to be always present, be it "+" or "-".
                    sign = ("-".equals(sign) ? "+" : "-");

                    // Always use "GMT" since that's required by Java API.
                    zone = "GMT" + sign + hours;

                    if (minutes != null) {
                        zone += minutes;
                    }
                }
            }

            // MRI behavior: With TZ equal to "GMT" or "UTC", Time.now
            // is *NOT* considered as a proper GMT/UTC time:
            //   ENV['TZ']="GMT"
            //   Time.now.gmt? ==> false
            //   ENV['TZ']="UTC"
            //   Time.now.utc? ==> false
            // Hence, we need to adjust for that.
            if ("GMT".equalsIgnoreCase(zone) || "UTC".equalsIgnoreCase(zone)) {
                zone = "Etc/" + zone;
            }

            DateTimeZone dtz = DateTimeZone.forTimeZone(TimeZone.getTimeZone(zone));
            runtime.getLocalTimezoneCache().put(originalZone, dtz);
            return dtz;
        }
    }

From source file:org.jruby.RubyTime.java

License:LGPL

public static DateTimeZone getLocalTimeZone(Ruby runtime) {
    IRubyObject tz = getEnvTimeZone(runtime);

    if (tz == null || !(tz instanceof RubyString)) {
        return DateTimeZone.getDefault();
    } else {// ww  w .j  ava2 s  . c o m
        return getTimeZoneFromTZString(runtime, tz.toString());
    }
}

From source file:org.jruby.truffle.core.time.GetTimeZoneNode.java

License:Open Source License

protected DateTimeZone getTimeZone(VirtualFrame frame) {
    Object tz = snippetNode.execute(frame, "ENV['TZ']");

    // TODO CS 4-May-15 not sure how TZ ends up being nil

    if (tz == nil()) {
        return DateTimeZone.getDefault();
    } else if (RubyGuards.isRubyString(tz)) {
        return TimeZoneParser.parse(this, StringOperations.getString((DynamicObject) tz));
    } else {//from  w  w w. j a v  a  2 s .co m
        throw new UnsupportedOperationException();
    }
}

From source file:org.jruby.truffle.nodes.time.ReadTimeZoneNode.java

License:Open Source License

@Override
public Object execute(VirtualFrame frame) {
    final Object tz = hashNode.call(frame, envNode.execute(frame), "[]", null, TZ);

    // TODO CS 4-May-15 not sure how TZ ends up being nil

    if (tz == nil()) {
        final String zone = DateTimeZone.getDefault().toString();
        return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(),
                RubyString.encodeBytelist(zone, UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
    } else if (RubyGuards.isRubyString(tz)) {
        return tz;
    } else {/*  w w w .j a va 2  s .  c o  m*/
        throw new UnsupportedOperationException();
    }
}

From source file:org.kalypso.commons.parser.impl.DateParser.java

License:Open Source License

public void setTimezone(final TimeZone tz) {
    if (tz == null)
        m_df = m_df.withZone(DateTimeZone.getDefault());
    else {/*from   www  . j  a va2s .c  o m*/
        final DateTimeZone zone = DateTimeZone.forTimeZone(tz);
        m_df = m_df.withZone(zone);
    }
}

From source file:org.logstash.filters.parser.TimestampParserFactory.java

License:Apache License

public static TimestampParser makeParser(String pattern, Locale locale, String zone) {
    if (locale == null) {
        locale = Locale.getDefault();
    }/* w w w . j  av a  2  s  . c  om*/

    if (zone == null) {
        zone = DateTimeZone.getDefault().getID();
    }

    switch (pattern) {
    case ISO8601: // Short-hand for a few ISO8601-ish formats
        return new CasualISO8601Parser(zone);
    case UNIX: // Unix epoch in seconds
        return new UnixEpochParser();
    case TAI64N: // TAI64N format
        return new TAI64NParser();
    case UNIX_MS: // Unix epoch in milliseconds
        return new UnixMillisEpochParser();
    default:
        if (zone.contains("%{")) {
            return new JodaParser(pattern, locale, null);
        } else {
            return new JodaParser(pattern, locale, zone);
        }
    }
}

From source file:org.mifos.test.acceptance.remote.DateTimeUpdaterRemoteTestingService.java

License:Open Source License

public TimeMachinePage setDateTime(DateTime dateTime) throws UnsupportedEncodingException {
    DateTimeZone defaultDateTimeZone = DateTimeZone.getDefault();
    return setDateTime(dateTime, defaultDateTimeZone);
}

From source file:org.mobicents.servlet.restcomm.RvdProjectsMigrator.java

License:Open Source License

private String getTimeStamp() {
    LocalDateTime date = LocalDateTime.now();
    DateTimeZone tz = DateTimeZone.getDefault();
    return new Timestamp(date.toDateTime(tz).toDateTime(DateTimeZone.UTC).getMillis()).toString();
}

From source file:org.mule.modules.quickbooks.utils.QBDateAdapter.java

License:Open Source License

public QBDateAdapter() {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    DateTimeParser[] parsers = { ISODateTimeFormat.dateTimeNoMillis().getParser(),
            ISODateTimeFormat.dateTime().getParser(),
            DateTimeFormat.forPattern("yyyy-MM-ddZ").withZone(DateTimeZone.getDefault()).getParser() };
    builder.append(ISODateTimeFormat.dateTimeNoMillis().getPrinter(), parsers);
    dateTimeFormatter = builder.toFormatter();
}

From source file:org.mulgara.store.stringpool.xa.SPDateImpl.java

License:Mozilla Public License

/** Guess the timezone offset the given time (date) was stored under */
private static int calcTZOffset(long time) {
    int minutes = new DateTime(time, DateTimeZone.UTC).getMinuteOfDay();
    return (minutes < 12 * 60) ? -minutes
            : (minutes > 12 * 60) ? 24 * 60 - minutes
                    : (DateTimeZone.getDefault().getOffset(time) > 0) ? -minutes : minutes;
}