1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package tests.support; 19 20 import java.util.Calendar; 21 import java.util.GregorianCalendar; 22 import java.util.TimeZone; 23 24 /** 25 * Sample java.util.TimeZone subclass to test getDSTSavings() and getOffset(long) 26 * APIs 27 */ 28 public class Support_TimeZone extends TimeZone { 29 private static final long serialVersionUID = 1L; 30 31 int rawOffset; 32 33 boolean useDaylightTime; 34 35 public Support_TimeZone(int rawOffset, boolean useDaylightTime) { 36 this.rawOffset = rawOffset; 37 this.useDaylightTime = useDaylightTime; 38 } 39 40 @Override 41 public int getRawOffset() { 42 return rawOffset; 43 } 44 45 /** 46 * let's assume this timezone has daylight savings from the 4th month till 47 * the 10th month of the year to ame things simple. 48 */ 49 @Override 50 public boolean inDaylightTime(java.util.Date p1) { 51 if (!useDaylightTime) { 52 return false; 53 } 54 GregorianCalendar cal = new GregorianCalendar(); 55 cal.setTime(p1); 56 int month = cal.get(Calendar.MONTH); 57 58 if (month > 4 && month < 10) { 59 return true; 60 } 61 return false; 62 } 63 64 @Override 65 public boolean useDaylightTime() { 66 return useDaylightTime; 67 } 68 69 /* 70 * return 0 to keep it simple, since this subclass is not used to test this 71 * method.. 72 */ 73 @Override 74 public int getOffset(int p1, int p2, int p3, int p4, int p5, int p6) { 75 return 0; 76 } 77 78 @Override 79 public void setRawOffset(int p1) { 80 rawOffset = p1; 81 } 82 } 83