2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package gov.nasa.jpf.test.java.text;
20 import gov.nasa.jpf.util.test.TestJPF;
22 import java.text.DateFormat;
23 import java.text.FieldPosition;
24 import java.text.SimpleDateFormat;
25 import java.util.Calendar;
26 import java.util.GregorianCalendar;
27 import java.util.TimeZone;
29 import org.junit.Test;
31 public class SimpleDateFormatTest extends TestJPF {
34 public void testFormatWithTimeZone() {
35 if (verifyNoPropertyViolation()) {
36 SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
37 TimeZone timeZone = TimeZone.getTimeZone("GMT");
38 df.setTimeZone(timeZone);
39 Calendar calendar = new GregorianCalendar(timeZone);
40 calendar.set(2010, 10, 10, 10, 10, 10);
41 String time = "10:10"; // some locales don't print the secs
42 assertTrue(df.format(calendar.getTime(), new StringBuffer(), new FieldPosition(0)).toString().contains(time));
43 df.setTimeZone(TimeZone.getTimeZone("EST"));
44 time = "5:10"; // see above
45 assertTrue(df.format(calendar.getTime(), new StringBuffer(), new FieldPosition(0)).toString().contains(time));