Java 类java.util.SimpleTimeZone 实例源码

项目:alfresco-repository    文件:CalendarHelpersTest.java   
/**
 * Checks we correctly build the Timezone for somewhere
 *  that doesn't have DST (eg Brisbane)
 */
@Test public void simpleTimeZoneNoDST() 
{
   SimpleTimeZone tz = CalendarTimezoneHelper.buildTimeZone(ICAL_TZ_BRISBANE);

   assertNotNull(tz);
   assertEquals("Brisbane", tz.getID());

   // Doesn't do DST
   assertEquals(false, tz.useDaylightTime());

   // Always 10 hours ahead
   assertEquals(10*60*60*1000, tz.getOffset(date(2011,3,1).getTime()));
   assertEquals(10*60*60*1000, tz.getOffset(date(2011,9,1).getTime()));
   assertEquals(10*60*60*1000, tz.getOffset(date(2011,11,1).getTime()));
}
项目:ibm-cos-sdk-java    文件:DateUtilsTest.java   
@Test
public void testIssue233() throws ParseException {
    // https://github.com/aws/aws-sdk-java/issues/233
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    sdf.setTimeZone(new SimpleTimeZone(0, "GMT"));
    final String edgeCase = "292278994-08-17T07:12:55.807Z";
    Date expected = sdf.parse(edgeCase);
    if (DEBUG)
        System.out.println("date: " + expected);
    String formatted = DateUtils.formatISO8601Date(expected);
    if (DEBUG)
        System.out.println("formatted: " + formatted);
    assertEquals(edgeCase, formatted);
    Date parsed = DateUtils.parseISO8601Date(edgeCase);
    if (DEBUG)
        System.out.println("parsed: " + parsed);
    assertEquals(expected, parsed);
    String reformatted = DateUtils.formatISO8601Date(parsed);
    assertEquals(edgeCase, reformatted);
}
项目:openjdk-jdk10    文件:TransitionTest.java   
public void Test4278609() {
    SimpleTimeZone tz = new SimpleTimeZone(0, "MyTimeZone",
                           /* DST start day: August, 1, 0:00 */
                           Calendar.AUGUST, 1, 0, 0,
                           /* DST end day: January, 1, 0:00 (wall-clock)*/
                           Calendar.JANUARY, 1, 0, 0,
                           60 * 60 * 1000);

    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));

    // setting a date using GMT zone just after the end rule of tz zone
    cal.clear();
    cal.set(Calendar.ERA, GregorianCalendar.AD);
    cal.set(1998, Calendar.DECEMBER, 31, 23, 01, 00);

    Date date = cal.getTime();

    int millis = cal.get(Calendar.HOUR_OF_DAY) * 3600000
                 + cal.get(Calendar.MINUTE) * 60000
                 + cal.get(Calendar.SECOND) * 1000
                 + cal.get(Calendar.MILLISECOND);
    /* we must use standard local time */
    millis += tz.getRawOffset();

    int offset = tz.getOffset(cal.get(Calendar.ERA),
                              cal.get(Calendar.YEAR),
                              cal.get(Calendar.MONTH),
                              cal.get(Calendar.DATE),
                              cal.get(Calendar.DAY_OF_WEEK),
                              millis);

    if (offset != 0) {
        SimpleDateFormat format = new SimpleDateFormat("dd MMM HH:mm:ss zzz",
                                                       Locale.US);
        format.setTimeZone(tz);
        errln("Wrong DST transition: " + tz
              + "\na date just after DST = " + format.format(date)
              + "\ngetOffset = " + offset);
    }
}
项目:BiglyBT    文件:Time.java   
/**
 * creates a time object from a given date - if the date is between 1950
 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime
 * is used.
 */
public Time(
    Date    date)
{
    SimpleTimeZone      tz = new SimpleTimeZone(0, "Z");
    SimpleDateFormat    dateF = new SimpleDateFormat("yyyyMMddHHmmss");

    dateF.setTimeZone(tz);

    String  d = dateF.format(date) + "Z";
    int     year = Integer.parseInt(d.substring(0, 4));

    if (year < 1950 || year > 2049)
    {
        time = new DERGeneralizedTime(d);
    }
    else
    {
        time = new DERUTCTime(d.substring(2));
    }
}
项目:ccu-historian    文件:SegmentedTimeline.java   
/**
 * Constructs a new segmented timeline, optionaly using another segmented
 * timeline as its base. This chaining of SegmentedTimelines allows further
 * segmentation into smaller timelines.
 *
 * If a base
 *
 * @param segmentSize the size of a segment in ms. This time unit will be
 *        used to compute the included and excluded segments of the
 *        timeline.
 * @param segmentsIncluded Number of consecutive segments to include.
 * @param segmentsExcluded Number of consecutive segments to exclude.
 */
public SegmentedTimeline(long segmentSize,
                         int segmentsIncluded,
                         int segmentsExcluded) {

    this.segmentSize = segmentSize;
    this.segmentsIncluded = segmentsIncluded;
    this.segmentsExcluded = segmentsExcluded;

    this.groupSegmentCount = this.segmentsIncluded + this.segmentsExcluded;
    this.segmentsIncludedSize = this.segmentsIncluded * this.segmentSize;
    this.segmentsExcludedSize = this.segmentsExcluded * this.segmentSize;
    this.segmentsGroupSize = this.segmentsIncludedSize
                             + this.segmentsExcludedSize;
    int offset = TimeZone.getDefault().getRawOffset();
    TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset);
    this.workingCalendarNoDST = new GregorianCalendar(z,
            Locale.getDefault());
}
项目:ccu-historian    文件:SegmentedTimeline.java   
/**
 * Returns the milliseconds for midnight of the first Monday after
 * 1-Jan-1900, ignoring daylight savings.
 *
 * @return The milliseconds.
 *
 * @since 1.0.7
 */
public static long firstMondayAfter1900() {
    int offset = TimeZone.getDefault().getRawOffset();
    TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset);

    // calculate midnight of first monday after 1/1/1900 relative to
    // current locale
    Calendar cal = new GregorianCalendar(z);
    cal.set(1900, 0, 1, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        cal.add(Calendar.DATE, 1);
    }
    //return cal.getTimeInMillis();
    // preceding code won't work with JDK 1.3
    return cal.getTime().getTime();
}
项目:Direct-File-Downloader    文件:Time.java   
/**
 * creates a time object from a given date - if the date is between 1950
 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime
 * is used.
 */
public Time(
    Date    date)
{
    SimpleTimeZone      tz = new SimpleTimeZone(0, "Z");
    SimpleDateFormat    dateF = new SimpleDateFormat("yyyyMMddHHmmss");

    dateF.setTimeZone(tz);

    String  d = dateF.format(date) + "Z";
    int     year = Integer.parseInt(d.substring(0, 4));

    if (year < 1950 || year > 2049)
    {
        time = new DERGeneralizedTime(d);
    }
    else
    {
        time = new DERUTCTime(d.substring(2));
    }
}
项目:Peking-University-Open-Research-Data-Platform    文件:DOIDataCiteServiceBean.java   
public static String generateTimeString() {
    StringBuilder guid = new StringBuilder();

    // Create a calendar to get the date formatted properly
    String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
    SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
    pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    Calendar calendar = new GregorianCalendar(pdt);
    Date trialTime = new Date();
    calendar.setTime(trialTime);
    guid.append(calendar.get(Calendar.YEAR));
    guid.append(calendar.get(Calendar.DAY_OF_YEAR));
    guid.append(calendar.get(Calendar.HOUR_OF_DAY));
    guid.append(calendar.get(Calendar.MINUTE));
    guid.append(calendar.get(Calendar.SECOND));
    guid.append(calendar.get(Calendar.MILLISECOND));
    double random = Math.random();
    guid.append(random);

    return guid.toString();
}
项目:JCVD    文件:StorableTimeFenceTest.java   
@Test
public void testEquals() {
    StorableTimeFence fence1 = StorableTimeFence.inInterval(2, 300);
    StorableTimeFence fence2 = StorableTimeFence.inInterval(2, 400);
    StorableTimeFence fence3 = StorableTimeFence.inIntervalOfDay(DAY_OF_WEEK_MONDAY, mTimeZone, 20, 300);
    StorableTimeFence fence4 = StorableTimeFence.inIntervalOfDay(DAY_OF_WEEK_MONDAY, mTimeZone, 20, 300);
    StorableTimeFence fence5 = StorableTimeFence.inIntervalOfDay(DAY_OF_WEEK_MONDAY, new SimpleTimeZone(3, "1"), 20, 400);
    StorableTimeFence fence6 = StorableTimeFence.aroundTimeInstant(TimeFence.TIME_INSTANT_SUNRISE, 0, 1);
    StorableTimeFence fence7 = StorableTimeFence.aroundTimeInstant(TimeFence.TIME_INSTANT_SUNRISE, 0, 1);
    StorableTimeFence fence8 = StorableTimeFence.inTimeInterval(TIME_INTERVAL_AFTERNOON);
    StorableTimeFence fence9 = StorableTimeFence.inTimeInterval(TimeFence.TIME_INTERVAL_WEEKDAY);

    assertThat(fence1.equals(fence1), is(true));
    assertThat(fence3.equals(fence4), is(true));
    assertThat(fence2.equals(null), is(false));
    assertThat(fence4.equals(fence5), is(false));
    assertThat(fence5.equals(fence6), is(false));
    assertThat(fence6.equals(fence7), is(true));
    assertThat(fence8.equals(fence9), is(false));
}
项目:aya-lang    文件:SegmentedTimeline.java   
/**
 * Constructs a new segmented timeline, optionaly using another segmented
 * timeline as its base. This chaining of SegmentedTimelines allows further
 * segmentation into smaller timelines.
 *
 * If a base
 *
 * @param segmentSize the size of a segment in ms. This time unit will be
 *        used to compute the included and excluded segments of the
 *        timeline.
 * @param segmentsIncluded Number of consecutive segments to include.
 * @param segmentsExcluded Number of consecutive segments to exclude.
 */
public SegmentedTimeline(long segmentSize,
                         int segmentsIncluded,
                         int segmentsExcluded) {

    this.segmentSize = segmentSize;
    this.segmentsIncluded = segmentsIncluded;
    this.segmentsExcluded = segmentsExcluded;

    this.groupSegmentCount = this.segmentsIncluded + this.segmentsExcluded;
    this.segmentsIncludedSize = this.segmentsIncluded * this.segmentSize;
    this.segmentsExcludedSize = this.segmentsExcluded * this.segmentSize;
    this.segmentsGroupSize = this.segmentsIncludedSize
                             + this.segmentsExcludedSize;
    int offset = TimeZone.getDefault().getRawOffset();
    TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset);
    this.workingCalendarNoDST = new GregorianCalendar(z,
            Locale.getDefault());
}
项目:aya-lang    文件:SegmentedTimeline.java   
/**
 * Returns the milliseconds for midnight of the first Monday after
 * 1-Jan-1900, ignoring daylight savings.
 *
 * @return The milliseconds.
 *
 * @since 1.0.7
 */
public static long firstMondayAfter1900() {
    int offset = TimeZone.getDefault().getRawOffset();
    TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset);

    // calculate midnight of first monday after 1/1/1900 relative to
    // current locale
    Calendar cal = new GregorianCalendar(z);
    cal.set(1900, 0, 1, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        cal.add(Calendar.DATE, 1);
    }
    //return cal.getTimeInMillis();
    // preceding code won't work with JDK 1.3
    return cal.getTime().getTime();
}
项目:Aki-SSL    文件:Time.java   
/**
 * Creates a time object from a given date - if the date is between 1950
 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime
 * is used.
 *
 * @param time a date object representing the time of interest.
 */
public Time(
    Date    time)
{
    SimpleTimeZone      tz = new SimpleTimeZone(0, "Z");
    SimpleDateFormat    dateF = new SimpleDateFormat("yyyyMMddHHmmss");

    dateF.setTimeZone(tz);

    String  d = dateF.format(time) + "Z";
    int     year = Integer.parseInt(d.substring(0, 4));

    if (year < 1950 || year > 2049)
    {
        this.time = new DERGeneralizedTime(d);
    }
    else
    {
        this.time = new DERUTCTime(d.substring(2));
    }
}
项目:Aki-SSL    文件:Time.java   
/**
 * Creates a time object from a given date and locale - if the date is between 1950
 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime
 * is used. You may need to use this constructor if the default locale
 * doesn't use a Gregorian calender so that the GeneralizedTime produced is compatible with other ASN.1 implementations.
 *
 * @param time a date object representing the time of interest.
 * @param locale an appropriate Locale for producing an ASN.1 GeneralizedTime value.
 */
public Time(
    Date    time,
    Locale locale)
{
    SimpleTimeZone      tz = new SimpleTimeZone(0, "Z");
    SimpleDateFormat    dateF = new SimpleDateFormat("yyyyMMddHHmmss", locale);

    dateF.setTimeZone(tz);

    String  d = dateF.format(time) + "Z";
    int     year = Integer.parseInt(d.substring(0, 4));

    if (year < 1950 || year > 2049)
    {
        this.time = new DERGeneralizedTime(d);
    }
    else
    {
        this.time = new DERUTCTime(d.substring(2));
    }
}
项目:Aki-SSL    文件:Time.java   
/**
 * Creates a time object from a given date - if the date is between 1950
 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime
 * is used.
 *
 * @param time a date object representing the time of interest.
 */
public Time(
    Date    time)
{
    SimpleTimeZone      tz = new SimpleTimeZone(0, "Z");
    SimpleDateFormat    dateF = new SimpleDateFormat("yyyyMMddHHmmss");

    dateF.setTimeZone(tz);

    String  d = dateF.format(time) + "Z";
    int     year = Integer.parseInt(d.substring(0, 4));

    if (year < 1950 || year > 2049)
    {
        this.time = new DERGeneralizedTime(d);
    }
    else
    {
        this.time = new DERUTCTime(d.substring(2));
    }
}
项目:Aki-SSL    文件:Time.java   
/**
 * Creates a time object from a given date and locale - if the date is between 1950
 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime
 * is used. You may need to use this constructor if the default locale
 * doesn't use a Gregorian calender so that the GeneralizedTime produced is compatible with other ASN.1 implementations.
 *
 * @param time a date object representing the time of interest.
 * @param locale an appropriate Locale for producing an ASN.1 GeneralizedTime value.
 */
public Time(
    Date    time,
    Locale locale)
{
    SimpleTimeZone      tz = new SimpleTimeZone(0, "Z");
    SimpleDateFormat    dateF = new SimpleDateFormat("yyyyMMddHHmmss", locale);

    dateF.setTimeZone(tz);

    String  d = dateF.format(time) + "Z";
    int     year = Integer.parseInt(d.substring(0, 4));

    if (year < 1950 || year > 2049)
    {
        this.time = new DERGeneralizedTime(d);
    }
    else
    {
        this.time = new DERUTCTime(d.substring(2));
    }
}
项目:intellij-ce-playground    文件:LocaleManagerTest.java   
public void testGetTimeZoneRegion() {
    assertEquals("PT", LocaleManager.getTimeZoneRegionAlpha2(
            TimeZone.getTimeZone("Europe/Lisbon")));
    assertEquals("PT", LocaleManager.getTimeZoneRegionAlpha2(
            TimeZone.getTimeZone("Atlantic/Azores")));
    assertEquals("PT", LocaleManager.getTimeZoneRegionAlpha2(
            TimeZone.getTimeZone("Atlantic/Azores")));

    assertEquals("BR", LocaleManager.getTimeZoneRegionAlpha2(
            TimeZone.getTimeZone("America/Araguaina")));

    assertEquals("US", LocaleManager.getTimeZoneRegionAlpha2(
            TimeZone.getTimeZone("America/Adak")));
    assertEquals("US", LocaleManager.getTimeZoneRegionAlpha2(
            TimeZone.getTimeZone("America/Anchorage")));
    assertEquals("US", LocaleManager.getTimeZoneRegionAlpha2(TimeZone.getTimeZone("PST")));

    // Test JDK variations
    assertEquals("LY", LocaleManager.getTimeZoneRegionAlpha2(
            TimeZone.getTimeZone("Africa/Tripoli")));
    assertEquals("LY", LocaleManager.getTimeZoneRegionAlpha2(
            new SimpleTimeZone(3600000, "Africa/Tripoli")));
    assertEquals("LY", LocaleManager.getTimeZoneRegionAlpha2(
            new SimpleTimeZone(7200000, "Africa/Tripoli"))); // changed in jdk8
    assertNull(LocaleManager.getTimeZoneRegionAlpha2(new SimpleTimeZone(-42, "Africa/Tripoli"))); // wrong
}
项目:sdrtrunk    文件:SyncBroadcast.java   
/**
 * Local time zone offset from UTC universal time (zulu) when the VALID 
 * LOCAL TIME OFFSET flag indicates a valid offset.  Otherwise, this method
 * returns a static +00:00 indicating no local time offset. 
 */
public TimeZone getTimeZone()
{
    if( isValidLocalTimeOffset() )
    {
        int offset = 0;

        offset += mMessage.getInt( LOCAL_TIME_OFFSET_HOURS ) * 3600000;
        offset += mMessage.get( LOCAL_TIME_OFFSET_HALF_HOUR ) ? 1800000 : 0;
        offset = mMessage.get( LOCAL_TIME_OFFSET_SIGN ) ? -offset : offset;

        return new SimpleTimeZone( offset, "LOCAL" );
    }
    else
    {
        return NO_TIME_ZONE;
    }
}
项目:sqp    文件:PGTimestampUtils.java   
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;

    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;
}
项目:aggregate    文件:TableConstants.java   
public static Long milliSecondsFromNanos(String timeNanos ) {
  if ( timeNanos == null ) return null;
  // convert from a nanosecond-extended iso8601-style UTC date yyyy-mm-ddTHH:MM:SS.sssssssss
  Calendar c = GregorianCalendar.getInstance(new SimpleTimeZone(0,"UT"));
  SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
  sf.setCalendar(c);
  String truncated = timeNanos.substring(0, timeNanos.length()-MILLI_TO_NANO_TIMESTAMP_EXTENSION.length());
  Date d;
  try {
    d = sf.parse(truncated);
  } catch (ParseException e) {
    e.printStackTrace();
    throw new IllegalArgumentException("Unrecognized time format: " + timeNanos);
  }
  Long v = d.getTime();
  return v;
}
项目:TinyTravelTracker    文件:Time.java   
/**
 * Creates a time object from a given date - if the date is between 1950
 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime
 * is used.
 *
 * @param time a date object representing the time of interest.
 */
public Time(
    Date    time)
{
    SimpleTimeZone      tz = new SimpleTimeZone(0, "Z");
    SimpleDateFormat    dateF = new SimpleDateFormat("yyyyMMddHHmmss");

    dateF.setTimeZone(tz);

    String  d = dateF.format(time) + "Z";
    int     year = Integer.parseInt(d.substring(0, 4));

    if (year < 1950 || year > 2049)
    {
        this.time = new DERGeneralizedTime(d);
    }
    else
    {
        this.time = new DERUTCTime(d.substring(2));
    }
}
项目:TinyTravelTracker    文件:Time.java   
/**
 * Creates a time object from a given date and locale - if the date is between 1950
 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime
 * is used. You may need to use this constructor if the default locale
 * doesn't use a Gregorian calender so that the GeneralizedTime produced is compatible with other ASN.1 implementations.
 *
 * @param time a date object representing the time of interest.
 * @param locale an appropriate Locale for producing an ASN.1 GeneralizedTime value.
 */
public Time(
    Date    time,
    Locale locale)
{
    SimpleTimeZone      tz = new SimpleTimeZone(0, "Z");
    SimpleDateFormat    dateF = new SimpleDateFormat("yyyyMMddHHmmss", locale);

    dateF.setTimeZone(tz);

    String  d = dateF.format(time) + "Z";
    int     year = Integer.parseInt(d.substring(0, 4));

    if (year < 1950 || year > 2049)
    {
        this.time = new DERGeneralizedTime(d);
    }
    else
    {
        this.time = new DERUTCTime(d.substring(2));
    }
}
项目:TinyTravelTracker    文件:Time.java   
/**
 * Creates a time object from a given date - if the date is between 1950
 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime
 * is used.
 *
 * @param time a date object representing the time of interest.
 */
public Time(
    Date    time)
{
    SimpleTimeZone      tz = new SimpleTimeZone(0, "Z");
    SimpleDateFormat    dateF = new SimpleDateFormat("yyyyMMddHHmmss");

    dateF.setTimeZone(tz);

    String  d = dateF.format(time) + "Z";
    int     year = Integer.parseInt(d.substring(0, 4));

    if (year < 1950 || year > 2049)
    {
        this.time = new DERGeneralizedTime(d);
    }
    else
    {
        this.time = new DERUTCTime(d.substring(2));
    }
}
项目:TinyTravelTracker    文件:Time.java   
/**
 * Creates a time object from a given date and locale - if the date is between 1950
 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime
 * is used. You may need to use this constructor if the default locale
 * doesn't use a Gregorian calender so that the GeneralizedTime produced is compatible with other ASN.1 implementations.
 *
 * @param time a date object representing the time of interest.
 * @param locale an appropriate Locale for producing an ASN.1 GeneralizedTime value.
 */
public Time(
    Date    time,
    Locale locale)
{
    SimpleTimeZone      tz = new SimpleTimeZone(0, "Z");
    SimpleDateFormat    dateF = new SimpleDateFormat("yyyyMMddHHmmss", locale);

    dateF.setTimeZone(tz);

    String  d = dateF.format(time) + "Z";
    int     year = Integer.parseInt(d.substring(0, 4));

    if (year < 1950 || year > 2049)
    {
        this.time = new DERGeneralizedTime(d);
    }
    else
    {
        this.time = new DERUTCTime(d.substring(2));
    }
}
项目:j2objc    文件:SimpleTimeZoneTest.java   
/**
 * @tests java.util.SimpleTimeZone#SimpleTimeZone(int, java.lang.String,
 *        int, int, int, int, int, int, int, int)
 */
public void test_ConstructorILjava_lang_StringIIIIIIII() {
    // Test for method java.util.SimpleTimeZone(int, java.lang.String, int,
    // int, int, int, int, int, int, int)
    SimpleTimeZone st = new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER,
            1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY,
            0);
    assertTrue("Incorrect TZ constructed", st
            .inDaylightTime(new GregorianCalendar(1998, Calendar.NOVEMBER,
                    13).getTime()));
    assertTrue("Incorrect TZ constructed", !(st
            .inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER,
                    13).getTime())));
    assertEquals("Incorrect TZ constructed", "TEST", st.getID());
    assertEquals("Incorrect TZ constructed", 1000, st.getRawOffset());
    assertTrue("Incorrect TZ constructed", st.useDaylightTime());
}
项目:j2objc    文件:SimpleTimeZoneTest.java   
/**
 * @tests java.util.SimpleTimeZone#SimpleTimeZone(int, java.lang.String,
 *        int, int, int, int, int, int, int, int, int)
 */
public void test_ConstructorILjava_lang_StringIIIIIIIII() {
    // Test for method java.util.SimpleTimeZone(int, java.lang.String, int,
    // int, int, int, int, int, int, int, int)
    SimpleTimeZone st = new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER,
            1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY,
            0, 1000 * 60 * 60);
    assertTrue("Incorrect TZ constructed", st
            .inDaylightTime(new GregorianCalendar(1998, Calendar.NOVEMBER,
                    13).getTime()));
    assertTrue("Incorrect TZ constructed", !(st
            .inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER,
                    13).getTime())));
    assertEquals("Incorrect TZ constructed", "TEST", st.getID());
    assertEquals("Incorrect TZ constructed", 1000, st.getRawOffset());
    assertTrue("Incorrect TZ constructed", st.useDaylightTime());
    assertTrue("Incorrect TZ constructed",
            st.getDSTSavings() == 1000 * 60 * 60);
}
项目:j2objc    文件:SimpleTimeZoneTest.java   
/**
 * @tests java.util.SimpleTimeZone#hasSameRules(java.util.TimeZone)
 */
public void test_hasSameRulesLjava_util_TimeZone() {
    // Test for method boolean
    // java.util.SimpleTimeZone.hasSameRules(java.util.TimeZone)
    SimpleTimeZone st = new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER,
            1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY,
            0);
    SimpleTimeZone sameAsSt = new SimpleTimeZone(1000, "REST",
            Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER,
            -1, Calendar.SUNDAY, 0);
    SimpleTimeZone notSameAsSt = new SimpleTimeZone(1000, "PEST",
            Calendar.NOVEMBER, 2, Calendar.SUNDAY, 0, Calendar.NOVEMBER,
            -1, Calendar.SUNDAY, 0);
    assertTrue("Time zones have same rules but return false", st
            .hasSameRules(sameAsSt));
    assertTrue("Time zones have different rules but return true", !st
            .hasSameRules(notSameAsSt));
}
项目:j2objc    文件:SimpleTimeZoneTest.java   
/**
 * @tests java.util.SimpleTimeZone#setEndRule(int, int, int, int)
 */
public void test_setEndRuleIIII() {
    // Test for method void java.util.SimpleTimeZone.setEndRule(int, int,
    // int, int)
    SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ");
    // Spec indicates that both end and start must be set or result is
    // undefined
    st.setStartRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0);
    st.setEndRule(Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0);
    assertTrue("StartRule improperly set1", st.useDaylightTime());
    assertTrue("StartRule improperly set2", st
            .inDaylightTime(new GregorianCalendar(1998, Calendar.NOVEMBER,
                    13).getTime()));
    assertTrue("StartRule improperly set3", !(st
            .inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER,
                    13).getTime())));
}
项目:j2objc    文件:SimpleTimeZoneTest.java   
/**
 * @tests java.util.SimpleTimeZone#setEndRule(int, int, int, int, boolean)
 */
public void test_setEndRuleIIIIZ() {
    // Test for method void java.util.SimpleTimeZone.setEndRule(int, int,
    // int, int, boolean)
       SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ");
    // Spec indicates that both end and start must be set or result is
    // undefined
    st.setStartRule(Calendar.NOVEMBER, 8, Calendar.SUNDAY, 1, false);
    st.setEndRule(Calendar.NOVEMBER, 15, Calendar.SUNDAY, 1, true);
    assertTrue("StartRule improperly set1", st.useDaylightTime());
    assertTrue("StartRule improperly set2", st
            .inDaylightTime((new GregorianCalendar(1999, Calendar.NOVEMBER,
                    7, 12, 0).getTime())));
    assertTrue("StartRule improperly set3", st
            .inDaylightTime((new GregorianCalendar(1999, Calendar.NOVEMBER,
                    20, 12, 0).getTime())));
    assertTrue("StartRule improperly set4", !(st
            .inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER,
                    6, 12, 0).getTime())));
    assertTrue("StartRule improperly set5", !(st
            .inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER,
                    21, 12, 0).getTime())));
}
项目:j2objc    文件:SimpleTimeZoneTest.java   
/**
 * @tests java.util.SimpleTimeZone#setStartRule(int, int, int)
 */
public void test_setStartRuleIII() {
    // Test for method void java.util.SimpleTimeZone.setStartRule(int, int,
    // int)
    SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ");
    // Spec indicates that both end and start must be set or result is
    // undefined
    st.setStartRule(Calendar.NOVEMBER, 1, 1);
    st.setEndRule(Calendar.DECEMBER, 1, 1);
    assertTrue("StartRule improperly set", st.useDaylightTime());
    assertTrue("StartRule improperly set", st
            .inDaylightTime((new GregorianCalendar(1998, Calendar.NOVEMBER,
                    13).getTime())));
    assertTrue("StartRule improperly set", !(st
            .inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER,
                    13).getTime())));

}
项目:j2objc    文件:SimpleTimeZoneTest.java   
/**
 * @tests java.util.SimpleTimeZone#setStartRule(int, int, int, int)
 */
public void test_setStartRuleIIII() {
    // Test for method void java.util.SimpleTimeZone.setStartRule(int, int,
    // int, int)
    SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ");
    // Spec indicates that both end and start must be set or result is
    // undefined
    st.setStartRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0);
    st.setEndRule(Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0);
    assertTrue("StartRule improperly set1", st.useDaylightTime());
    assertTrue("StartRule improperly set2", st
            .inDaylightTime((new GregorianCalendar(1998, Calendar.NOVEMBER,
                    13).getTime())));
    assertTrue("StartRule improperly set3", !(st
            .inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER,
                    13).getTime())));
}
项目:j2objc    文件:SimpleTimeZoneTest.java   
/**
 * @tests java.util.SimpleTimeZone#setStartRule(int, int, int, int, boolean)
 */
public void test_setStartRuleIIIIZ() {
    // Test for method void java.util.SimpleTimeZone.setStartRule(int, int,
    // int, int, boolean)
       SimpleTimeZone st = new SimpleTimeZone(0, "Test");
    // Spec indicates that both end and start must be set or result is
    // undefined
    st.setStartRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 1, true);
    st.setEndRule(Calendar.NOVEMBER, 15, Calendar.SUNDAY, 1, false);
    assertTrue("StartRule improperly set1", st.useDaylightTime());
    assertTrue("StartRule improperly set2", st
            .inDaylightTime((new GregorianCalendar(1999, Calendar.NOVEMBER,
                    7, 12, 0).getTime())));
    assertTrue("StartRule improperly set3", st
            .inDaylightTime((new GregorianCalendar(1999, Calendar.NOVEMBER,
                    13, 12, 0).getTime())));
    assertTrue("StartRule improperly set4", !(st
            .inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER,
                    6, 12, 0).getTime())));
    assertTrue("StartRule improperly set5", !(st
            .inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER,
                    14, 12, 0).getTime())));
}
项目:j2objc    文件:SimpleTimeZoneTest.java   
/**
 * @tests java.util.SimpleTimeZone#setStartYear(int)
 */
public void test_setStartYearI() {
    // Test for method void java.util.SimpleTimeZone.setStartYear(int)
    SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ");
    st.setStartRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0);
    st.setEndRule(Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0);
    st.setStartYear(1999);
    assertTrue("set year improperly set1", !(st
            .inDaylightTime(new GregorianCalendar(1999, Calendar.JULY, 12)
                    .getTime())));
    assertTrue("set year improperly set2", !(st
            .inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER,
                    13).getTime())));
    assertTrue("set year improperly set3", (st
            .inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER,
                    13).getTime())));
}
项目:metasfresh    文件:CCPaymentReserveProcess.java   
/**
 * Calculates the reserve date.
 *
 * @param deliveryTime
 * @return
 */
private Timestamp getReserveDate() {
    final SimpleTimeZone mez = new SimpleTimeZone(+1 * 60 * 60 * 1000, "ECT");
    mez.setStartRule(Calendar.MARCH, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    mez.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    final Calendar cal = GregorianCalendar.getInstance(mez);
    // wenn nach x Uhr, einen Tag aufschlagen
    // cal.add(Calendar.DAY_OF_MONTH, 1);

    for (int i = 0; i < TIME_BEFORE_PROMISED; i++) {
        cal.add(Calendar.DAY_OF_MONTH, 1);
        final int weekday = cal.get(Calendar.DAY_OF_WEEK);
        // wenn das promisedDate auf das Wochenende f�llt, auf Montag
        // verschieben
        if (weekday == 0) { // Sonntag
            cal.add(Calendar.DAY_OF_MONTH, 1);
        } else if (weekday == 7) { // Samstag
            cal.add(Calendar.DAY_OF_MONTH, 2);
        }
    }
    return new Timestamp(cal.getTimeInMillis());
}
项目:HTML5_WebSite    文件:SegmentedTimeline.java   
/**
 * Constructs a new segmented timeline, optionaly using another segmented
 * timeline as its base. This chaining of SegmentedTimelines allows further
 * segmentation into smaller timelines.
 *
 * If a base
 *
 * @param segmentSize the size of a segment in ms. This time unit will be
 *        used to compute the included and excluded segments of the
 *        timeline.
 * @param segmentsIncluded Number of consecutive segments to include.
 * @param segmentsExcluded Number of consecutive segments to exclude.
 */
public SegmentedTimeline(long segmentSize,
                         int segmentsIncluded,
                         int segmentsExcluded) {

    this.segmentSize = segmentSize;
    this.segmentsIncluded = segmentsIncluded;
    this.segmentsExcluded = segmentsExcluded;

    this.groupSegmentCount = this.segmentsIncluded + this.segmentsExcluded;
    this.segmentsIncludedSize = this.segmentsIncluded * this.segmentSize;
    this.segmentsExcludedSize = this.segmentsExcluded * this.segmentSize;
    this.segmentsGroupSize = this.segmentsIncludedSize
                             + this.segmentsExcludedSize;
    int offset = TimeZone.getDefault().getRawOffset();
    TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset);
    this.workingCalendarNoDST = new GregorianCalendar(z,
            Locale.getDefault());
}
项目:HTML5_WebSite    文件:SegmentedTimeline.java   
/**
 * Returns the milliseconds for midnight of the first Monday after
 * 1-Jan-1900, ignoring daylight savings.
 *
 * @return The milliseconds.
 *
 * @since 1.0.7
 */
public static long firstMondayAfter1900() {
    int offset = TimeZone.getDefault().getRawOffset();
    TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset);

    // calculate midnight of first monday after 1/1/1900 relative to
    // current locale
    Calendar cal = new GregorianCalendar(z);
    cal.set(1900, 0, 1, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        cal.add(Calendar.DATE, 1);
    }
    //return cal.getTimeInMillis();
    // preceding code won't work with JDK 1.3
    return cal.getTime().getTime();
}
项目:populus    文件:SegmentedTimeline.java   
/**
 * Constructs a new segmented timeline, optionaly using another segmented
 * timeline as its base. This chaining of SegmentedTimelines allows further
 * segmentation into smaller timelines.
 *
 * If a base
 *
 * @param segmentSize the size of a segment in ms. This time unit will be
 *        used to compute the included and excluded segments of the
 *        timeline.
 * @param segmentsIncluded Number of consecutive segments to include.
 * @param segmentsExcluded Number of consecutive segments to exclude.
 */
public SegmentedTimeline(long segmentSize,
                         int segmentsIncluded,
                         int segmentsExcluded) {

    this.segmentSize = segmentSize;
    this.segmentsIncluded = segmentsIncluded;
    this.segmentsExcluded = segmentsExcluded;

    this.groupSegmentCount = this.segmentsIncluded + this.segmentsExcluded;
    this.segmentsIncludedSize = this.segmentsIncluded * this.segmentSize;
    this.segmentsExcludedSize = this.segmentsExcluded * this.segmentSize;
    this.segmentsGroupSize = this.segmentsIncludedSize
                             + this.segmentsExcludedSize;
    int offset = TimeZone.getDefault().getRawOffset();
    TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset);
    this.workingCalendarNoDST = new GregorianCalendar(z,
            Locale.getDefault());
}
项目:populus    文件:SegmentedTimeline.java   
/**
 * Returns the milliseconds for midnight of the first Monday after
 * 1-Jan-1900, ignoring daylight savings.
 *
 * @return The milliseconds.
 *
 * @since 1.0.7
 */
public static long firstMondayAfter1900() {
    int offset = TimeZone.getDefault().getRawOffset();
    TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset);

    // calculate midnight of first monday after 1/1/1900 relative to
    // current locale
    Calendar cal = new GregorianCalendar(z);
    cal.set(1900, 0, 1, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        cal.add(Calendar.DATE, 1);
    }
    //return cal.getTimeInMillis();
    // preceding code won't work with JDK 1.3
    return cal.getTime().getTime();
}
项目:SyntacticParsing    文件:StringUtil.java   
/** ***************************************************************
 * Returns a date/time string corresponding to pattern.  The
 * date/time returned is the date/time of the method call.  The
 * locale is UTC (Greenwich).
 *
 * @param pattern Examples: yyyy, yyyy-MM-dd.
 *
 */
public static String getDateTime(String pattern) {

    String dateTime = "";
    try {
        if (isNonEmptyString(pattern)) {
            SimpleDateFormat sdf = new SimpleDateFormat(pattern);
            sdf.setTimeZone(new SimpleTimeZone(0, "Greenwich"));
            dateTime = sdf.format(new Date());
        }
    }
    catch (Exception ex) {
        ex.printStackTrace();
    }
    return dateTime;
}
项目:box-android-sdk    文件:BoxDateFormat.java   
private static TimeZone getTimeZone(final String offset) {
    TimeZone cached = mTimeZones.get(offset);
    if (cached != null) {
        return cached;
    }
    int parseOffset = 0;
    // Fix for devices that run on Java6, as the parseInt from Integer class cannot handle
    //  the plus sign ("+") on the beginning.
    if(offset.charAt(0) == '+') {
        parseOffset++;
    }
    Integer offsetHours = Integer.parseInt(offset.substring(parseOffset, 3));
    // Parse any minute offset as well
    Integer offsetMinutes = Integer.parseInt((offset.substring(4)));
    int offsetMiliSec = offsetHours * MILLIS_PER_HOUR;
    if (offsetHours < 0) {
        offsetMiliSec -= (offsetMinutes * MILLIS_PER_MINUTE);
    } else {
        offsetMiliSec += (offsetMinutes * MILLIS_PER_MINUTE);
    }
    TimeZone zone = new SimpleTimeZone(offsetMiliSec, offset);
    mTimeZones.put(offset, zone);
    return zone;
}
项目:PI    文件:SegmentedTimeline.java   
/**
 * Constructs a new segmented timeline, optionaly using another segmented
 * timeline as its base. This chaining of SegmentedTimelines allows further
 * segmentation into smaller timelines.
 *
 * If a base
 *
 * @param segmentSize the size of a segment in ms. This time unit will be
 *        used to compute the included and excluded segments of the
 *        timeline.
 * @param segmentsIncluded Number of consecutive segments to include.
 * @param segmentsExcluded Number of consecutive segments to exclude.
 */
public SegmentedTimeline(long segmentSize,
                         int segmentsIncluded,
                         int segmentsExcluded) {

    this.segmentSize = segmentSize;
    this.segmentsIncluded = segmentsIncluded;
    this.segmentsExcluded = segmentsExcluded;

    this.groupSegmentCount = this.segmentsIncluded + this.segmentsExcluded;
    this.segmentsIncludedSize = this.segmentsIncluded * this.segmentSize;
    this.segmentsExcludedSize = this.segmentsExcluded * this.segmentSize;
    this.segmentsGroupSize = this.segmentsIncludedSize
                             + this.segmentsExcludedSize;
    int offset = TimeZone.getDefault().getRawOffset();
    TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset);
    this.workingCalendarNoDST = new GregorianCalendar(z,
            Locale.getDefault());
}