Search in sources :

Example 51 with SimpleTimeZone

use of java.util.SimpleTimeZone in project joda-time by JodaOrg.

the class TestLocalDate_Basics method testToDate_autumnDST.

public void testToDate_autumnDST() {
    LocalDate base = new LocalDate(2007, 10, 2);
    SimpleTimeZone testZone = new SimpleTimeZone(3600000, "NoMidnight", Calendar.APRIL, 2, 0, 0, Calendar.OCTOBER, 2, 0, 3600000);
    TimeZone currentZone = TimeZone.getDefault();
    try {
        TimeZone.setDefault(testZone);
        Date test = base.toDate();
        check(base, 2007, 10, 2);
        assertEquals("Tue Oct 02 00:00:00 GMT+02:00 2007", test.toString());
    } finally {
        TimeZone.setDefault(currentZone);
    }
}
Also used : TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleTimeZone(java.util.SimpleTimeZone) Date(java.util.Date)

Example 52 with SimpleTimeZone

use of java.util.SimpleTimeZone in project opennms by OpenNMS.

the class TimestampUtils method getCalendar.

/**
 * True if the backend uses doubles for time values. False if long is used.
 */
private Calendar getCalendar(int sign, int hr, int min, int sec) {
    int rawOffset = sign * (((hr * 60 + min) * 60 + sec) * 1000);
    if (calCache != null && calCacheZone == rawOffset)
        return calCache;
    final StringBuilder zoneID = new StringBuilder("GMT");
    zoneID.append(sign < 0 ? '-' : '+');
    if (hr < 10)
        zoneID.append('0');
    zoneID.append(hr);
    if (min < 10)
        zoneID.append('0');
    zoneID.append(min);
    if (sec < 10)
        zoneID.append('0');
    zoneID.append(sec);
    TimeZone syntheticTZ = new SimpleTimeZone(rawOffset, zoneID.toString());
    calCache = new GregorianCalendar(syntheticTZ);
    calCacheZone = rawOffset;
    return calCache;
}
Also used : TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleTimeZone(java.util.SimpleTimeZone) GregorianCalendar(java.util.GregorianCalendar)

Example 53 with SimpleTimeZone

use of java.util.SimpleTimeZone in project jphp by jphp-compiler.

the class WrapTimeZone method __construct.

@Signature({ @Arg("rawOffset"), @Arg("ID"), @Arg(value = "properties", type = HintType.ARRAY, optional = @Optional("null")) })
public Memory __construct(Environment env, Memory... args) {
    if (args[2].isNull()) {
        timeZone = new SimpleTimeZone(args[0].toInteger(), args[1].toString());
    } else {
        ArrayMemory props = args[2].toValue(ArrayMemory.class);
        int startMonth = props.valueOfIndex("start_month").toInteger();
        int startDay = props.valueOfIndex("start_day").toInteger();
        int startDayOfWeek = props.valueOfIndex("start_day_of_week").toInteger();
        int startTime = props.valueOfIndex("start_time").toInteger();
        int endMonth = props.valueOfIndex("end_month").toInteger();
        int endDay = props.valueOfIndex("end_day").toInteger();
        int endDayOfWeek = props.valueOfIndex("end_day_of_week").toInteger();
        int endTime = props.valueOfIndex("end_time").toInteger();
        timeZone = new SimpleTimeZone(args[0].toInteger(), args[1].toString(), startMonth, startDay, startDayOfWeek, startTime, endMonth, endDay, endDayOfWeek, endTime);
    }
    return Memory.NULL;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) SimpleTimeZone(java.util.SimpleTimeZone)

Example 54 with SimpleTimeZone

use of java.util.SimpleTimeZone in project hibernate-orm by hibernate.

the class TypeTest method testTimeZoneType.

@Test
public void testTimeZoneType() {
    final TimeZone original = new SimpleTimeZone(-1, "abc");
    final TimeZone copy = new SimpleTimeZone(-1, "abc");
    final TimeZone different = new SimpleTimeZone(-2, "xyz");
    runBasicTests(TimeZoneType.INSTANCE, original, copy, different);
}
Also used : TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleTimeZone(java.util.SimpleTimeZone) Test(org.junit.Test)

Example 55 with SimpleTimeZone

use of java.util.SimpleTimeZone in project j2objc by google.

the class SimpleDateFormatTest method test_format_time_zones.

public void test_format_time_zones() throws Exception {
    Calendar cal = new GregorianCalendar(1999, Calendar.JUNE, 2, 15, 3, 6);
    SimpleDateFormat format = new SimpleDateFormat("", Locale.ENGLISH);
    format.setTimeZone(TimeZone.getTimeZone("EST"));
    assertFormat(format, " z", cal, " GMT-5", DateFormat.TIMEZONE_FIELD);
    Calendar temp2 = new GregorianCalendar(1999, Calendar.JANUARY, 12);
    assertFormat(format, " z", temp2, " GMT-5", DateFormat.TIMEZONE_FIELD);
    assertFormat(format, " zz", cal, " GMT-5", DateFormat.TIMEZONE_FIELD);
    assertFormat(format, " zzz", cal, " GMT-5", DateFormat.TIMEZONE_FIELD);
    assertFormat(format, " zzzz", cal, " GMT-05:00", DateFormat.TIMEZONE_FIELD);
    assertFormat(format, " zzzz", temp2, " GMT-05:00", DateFormat.TIMEZONE_FIELD);
    assertFormat(format, " zzzzz", cal, " GMT-05:00", DateFormat.TIMEZONE_FIELD);
    format.setTimeZone(TimeZone.getTimeZone("America/New_York"));
    assertFormat(format, " z", cal, " EDT", DateFormat.TIMEZONE_FIELD);
    assertFormat(format, " z", temp2, " EST", DateFormat.TIMEZONE_FIELD);
    assertFormat(format, " zz", cal, " EDT", DateFormat.TIMEZONE_FIELD);
    assertFormat(format, " zzz", cal, " EDT", DateFormat.TIMEZONE_FIELD);
    assertFormat(format, " zzzz", cal, " Eastern Daylight Time", DateFormat.TIMEZONE_FIELD);
    assertFormat(format, " zzzz", temp2, " Eastern Standard Time", DateFormat.TIMEZONE_FIELD);
    assertFormat(format, " zzzzz", cal, " Eastern Daylight Time", DateFormat.TIMEZONE_FIELD);
    TimeZone tz0001 = new SimpleTimeZone(60000, "ONE MINUTE");
    TimeZone tz0130 = new SimpleTimeZone(5400000, "ONE HOUR, THIRTY");
    TimeZone tzMinus0130 = new SimpleTimeZone(-5400000, "NEG ONE HOUR, THIRTY");
    format.setTimeZone(tz0001);
    //        test(" Z", cal, " +0001", DateFormat.TIMEZONE_FIELD);
    //        test(" ZZZZ", cal, " GMT+00:01", DateFormat.TIMEZONE_FIELD);
    //        test(" ZZZZZ", cal, " +00:01", DateFormat.TIMEZONE_FIELD);
    format.setTimeZone(tz0130);
    //        test(" Z", cal, " +0130", DateFormat.TIMEZONE_FIELD);
    format.setTimeZone(tzMinus0130);
    //        test(" Z", cal, " -0130", DateFormat.TIMEZONE_FIELD);
    format.setTimeZone(tz0001);
    assertFormat(format, " z", cal, " GMT+00:01", DateFormat.TIMEZONE_FIELD);
    assertFormat(format, " zzzz", cal, " GMT+00:01", DateFormat.TIMEZONE_FIELD);
    format.setTimeZone(tz0130);
    assertFormat(format, " z", cal, " GMT+01:30", DateFormat.TIMEZONE_FIELD);
    format.setTimeZone(tzMinus0130);
    assertFormat(format, " z", cal, " GMT-01:30", DateFormat.TIMEZONE_FIELD);
}
Also used : TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleTimeZone(java.util.SimpleTimeZone) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

SimpleTimeZone (java.util.SimpleTimeZone)114 TimeZone (java.util.TimeZone)42 GregorianCalendar (java.util.GregorianCalendar)34 Date (java.util.Date)25 SimpleDateFormat (java.text.SimpleDateFormat)20 Calendar (java.util.Calendar)8 Test (org.junit.Test)7 BasicDBObject (com.mongodb.BasicDBObject)3 BSONTimestamp (org.bson.types.BSONTimestamp)3 Code (org.bson.types.Code)3 CodeWScope (org.bson.types.CodeWScope)3 ObjectId (org.bson.types.ObjectId)3 Support_TimeZone (tests.support.Support_TimeZone)3 DBRef (com.mongodb.DBRef)2 IOException (java.io.IOException)2 InvalidObjectException (java.io.InvalidObjectException)2 DateFormat (java.text.DateFormat)2 ParsePosition (java.text.ParsePosition)2 Binary (org.bson.types.Binary)2 MaxKey (org.bson.types.MaxKey)2