File: check12.java

package info (click to toggle)
mauve 20120103-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 28,504 kB
  • sloc: java: 250,155; sh: 2,834; xml: 208; makefile: 66
file content (155 lines) | stat: -rw-r--r-- 6,948 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Test SimpleTimeZone.check12().

// Written by Jerry Quinn <jlquinn@optonline.net>

// This file is part of Mauve.

// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.

// Mauve is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING.  If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.

// Tags: JDK1.2

// Test features added by JDK 1.2

package gnu.testlet.java.util.SimpleTimeZone;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.SimpleTimeZone;
import java.util.TimeZone;

public class check12 implements Testlet
{
  public void test (TestHarness harness)
  {
    int rawOff = -18000000;	// 5 hours
    int dstOff = 3600000;	// 1 hour

    // Create a timezone for UTC-5 with daylight savings starting on
    // the second Monday, April 10 at 12 noon, ending the second
    // Sunday, September 10, 12 noon in daylight savings, 1 hour
    // shift.

    // All three should represent the same period
    SimpleTimeZone tz =
      new SimpleTimeZone(rawOff, "Z1",
			 Calendar.APRIL, 10, 0, 43200000,
			 Calendar.SEPTEMBER, 10, 0, 43200000,
			 dstOff);

    int off;

    // Test 1/2 hour before dst
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 10, Calendar.SATURDAY, 41400000);
    harness.check(off, rawOff);            // check 1
    
    // Test 1/2 hour into dst
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 10, Calendar.SATURDAY, 45000000);
    harness.check(off, rawOff + dstOff);   // check 2

    // Test end rule
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 41400000 - dstOff);
    harness.check(off, rawOff + dstOff);   // check 3
    
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 45000000 - dstOff);
    harness.check(off, rawOff);            // check 4

    // Test that Nth dayofweek works with day of month rules
    tz.setStartRule(Calendar.APRIL, 2, Calendar.SATURDAY, 43200000);

    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 10, Calendar.SATURDAY, 41400000);
    harness.check(off, rawOff);            // check 5
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 10, Calendar.SATURDAY, 45000000);
    harness.check(off, rawOff + dstOff);   // check 6

    tz.setEndRule(Calendar.SEPTEMBER, 2, Calendar.FRIDAY, 43200000);

    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 41400000 - dstOff);
    harness.check(off, rawOff + dstOff);   // check 7
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 45000000 - dstOff);
    harness.check(off, rawOff);            // check 8

    // Test that -Nth dayofweek works with day of month rules
    tz.setStartRule(Calendar.APRIL, -3, Calendar.SATURDAY, 43200000);

    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 10, Calendar.SATURDAY, 41400000);
    harness.check(off, rawOff);            // check 9
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 10, Calendar.SATURDAY, 45000000);
    harness.check(off, rawOff + dstOff);   // check 10

    tz.setEndRule(Calendar.SEPTEMBER, -3, Calendar.FRIDAY, 43200000);

    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 41400000 - dstOff);
    harness.check(off, rawOff + dstOff);   // check 11
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 45000000 - dstOff);
    harness.check(off, rawOff);            // check 12

    // Friday on or before April 5, 2004 is April 2
    // Test arguments get overidden and perform correctly
    tz.setStartRule(Calendar.APRIL, 5, Calendar.FRIDAY, 43200000, false);
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 2, Calendar.FRIDAY, 41400000);
    harness.check(off, rawOff);            // check 13
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 2, Calendar.FRIDAY, 45000000);
    harness.check(off, rawOff + dstOff);   // check 14
    
    tz.setEndRule(Calendar.SEPTEMBER, -15, -Calendar.FRIDAY, 43200000);

    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 41400000 - dstOff);
    harness.check(off, rawOff + dstOff);   // check 15
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 45000000 - dstOff);
    harness.check(off, rawOff);            // check 16

    // Sunday on or after April 5, 2004 is April 11
    // Test arguments get overidden and perform correctly
    tz.setStartRule(Calendar.APRIL, 5, Calendar.SUNDAY, 43200000, true);

    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 11, Calendar.SUNDAY, 41400000);
    harness.check(off, rawOff);            // check 17
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 11, Calendar.SUNDAY, 45000000);
    harness.check(off, rawOff + dstOff);   // check 18

    tz.setEndRule(Calendar.SEPTEMBER, 6, -Calendar.FRIDAY, 43200000);

    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 41400000 - dstOff);
    harness.check(off, rawOff + dstOff);   // check 19
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 45000000 - dstOff);
    harness.check(off, rawOff);            // check 20

    // Currently broken in GCJ
    tz.setEndRule(Calendar.SEPTEMBER, -6, -Calendar.TUESDAY, 43200000);

    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.AUGUST, 31, Calendar.TUESDAY, 41400000 - dstOff);
    harness.check(off, rawOff + dstOff);   // check 21
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.AUGUST, 31, Calendar.TUESDAY, 45000000 - dstOff);
    harness.check(off, rawOff);            // check 22

    // This looks like a Date or DateFormat test, but is here because there was a bug in SimpleTimeZone
    // PR libgcj/8321
    Date date = new Date(1034705556525l);
    TimeZone zone  = TimeZone.getTimeZone("EST");
    DateFormat dateFormat = DateFormat.getDateTimeInstance(
                        DateFormat.SHORT,
                        DateFormat.LONG,
                        Locale.US);
    dateFormat.setTimeZone(zone);
    harness.check(dateFormat.format(date), "10/15/02 2:12:36 PM EDT");
  }
}