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 18package tests.support; 19 20import java.util.Calendar; 21import java.util.GregorianCalendar; 22import java.util.TimeZone; 23 24/** 25 * Sample java.util.TimeZone subclass to test getDSTSavings() and getOffset(long) 26 * APIs 27 * 28 */ 29public class Support_TimeZone extends TimeZone { 30 private static final long serialVersionUID = 1L; 31 32 int rawOffset; 33 34 boolean useDaylightTime; 35 36 public Support_TimeZone(int rawOffset, boolean useDaylightTime) { 37 this.rawOffset = rawOffset; 38 this.useDaylightTime = useDaylightTime; 39 } 40 41 @Override 42 public int getRawOffset() { 43 return rawOffset; 44 } 45 46 /** 47 * let's assume this timezone has daylight savings from the 4th month till 48 * the 10th month of the year to ame things simple. 49 */ 50 @Override 51 public boolean inDaylightTime(java.util.Date p1) { 52 if (!useDaylightTime) { 53 return false; 54 } 55 GregorianCalendar cal = new GregorianCalendar(); 56 cal.setTime(p1); 57 int month = cal.get(Calendar.MONTH); 58 59 if (month > 4 && month < 10) { 60 return true; 61 } 62 return false; 63 } 64 65 @Override 66 public boolean useDaylightTime() { 67 return useDaylightTime; 68 } 69 70 /* 71 * return 0 to keep it simple, since this subclass is not used to test this 72 * method.. 73 */ 74 @Override 75 public int getOffset(int p1, int p2, int p3, int p4, int p5, int p6) { 76 return 0; 77 } 78 79 @Override 80 public void setRawOffset(int p1) { 81 rawOffset = p1; 82 } 83} 84