/** * Sets the daylight saving time start rule to a fixed date within a month. * This method is equivalent to: * <pre><code>setStartRule(startMonth, startDay, 0, startTime)</code></pre> * * @param startMonth The daylight saving time starting month. Month is * a {@link Calendar#MONTH MONTH} field * value (0-based. e.g., 0 for January). * @param startDay The day of the month on which the daylight saving time starts. * @param startTime The daylight saving time starting time in local wall clock * time, which is local standard time in this case. * See the class description for the special cases of this parameter. * @exception IllegalArgumentException if the <code>startMonth</code>, * <code>startDayOfMonth</code>, or <code>startTime</code> parameters are out of range * @since 1.2 */ public void setStartRule(int startMonth, int startDay, int startTime) { setStartRule(startMonth, startDay, 0, startTime); }
/** * Sets the daylight saving time start rule to a fixed date within a month. * This method is equivalent to: * <pre><code>setStartRule(startMonth, startDay, 0, startTime)</code></pre> * * @param startMonth The daylight saving time starting month. Month is * a {@link Calendar#MONTH MONTH} field * value (0-based. e.g., 0 for January). * @param startDay The day of the month on which the daylight saving time starts. * @param startTime The daylight saving time starting time in local wall clock * time, which is local standard time in this case. * See the class description for the special cases of this parameter. * @exception IllegalArgumentException if the <code>startMonth</code>, * <code>startDayOfMonth</code>, or <code>startTime</code> parameters are out of range * @since 1.2 */ public void setStartRule(int startMonth, int startDay, int startTime) { setStartRule(startMonth, startDay, 0, startTime); }
/** * Sets the daylight saving time start rule to a weekday before or after the given date within * a month, e.g., the first Monday on or after the 8th. * * @param startMonth The daylight saving time starting month. Month is * a {@link Calendar#MONTH MONTH} field * value (0-based. e.g., 0 for January). * @param startDay The day of the month on which the daylight saving time starts. * @param startDayOfWeek The daylight saving time starting day-of-week. * @param startTime The daylight saving time starting time in local wall clock * time, which is local standard time in this case. * @param after If true, this rule selects the first <code>dayOfWeek</code> on or * <em>after</em> <code>dayOfMonth</code>. If false, this rule * selects the last <code>dayOfWeek</code> on or <em>before</em> * <code>dayOfMonth</code>. * @exception IllegalArgumentException if the <code>startMonth</code>, <code>startDay</code>, * <code>startDayOfWeek</code>, or <code>startTime</code> parameters are out of range * @since 1.2 */ public void setStartRule(int startMonth, int startDay, int startDayOfWeek, int startTime, boolean after) { // TODO: this method doesn't check the initial values of dayOfMonth or dayOfWeek. if (after) { setStartRule(startMonth, startDay, -startDayOfWeek, startTime); } else { setStartRule(startMonth, -startDay, -startDayOfWeek, startTime); } }
/** * Sets the daylight saving time start rule to a weekday before or after the given date within * a month, e.g., the first Monday on or after the 8th. * * @param startMonth The daylight saving time starting month. Month is * a {@link Calendar#MONTH MONTH} field * value (0-based. e.g., 0 for January). * @param startDay The day of the month on which the daylight saving time starts. * @param startDayOfWeek The daylight saving time starting day-of-week. * @param startTime The daylight saving time starting time in local wall clock * time, which is local standard time in this case. * @param after If true, this rule selects the first <code>dayOfWeek</code> on or * <em>after</em> <code>dayOfMonth</code>. If false, this rule * selects the last <code>dayOfWeek</code> on or <em>before</em> * <code>dayOfMonth</code>. * @exception IllegalArgumentException if the <code>startMonth</code>, <code>startDay</code>, * <code>startDayOfWeek</code>, or <code>startTime</code> parameters are out of range * @since 1.2 */ public void setStartRule(int startMonth, int startDay, int startDayOfWeek, int startTime, boolean after) { // TODO: this method doesn't check the initial values of dayOfMonth or dayOfWeek. if (after) { setStartRule(startMonth, startDay, -startDayOfWeek, startTime); } else { setStartRule(startMonth, -startDay, -startDayOfWeek, startTime); } }
SimpleTimeZone est = new SimpleTimeZone(-5 * 60 * 60 * 1000, "EST"); est.setStartRule(Calendar.MARCH, 8, -Calendar.SUNDAY, 2 * 60 * 60 * 1000); est.setEndRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); Calendar testDateEndOut = new GregorianCalendar(est); testDateEndOut.set(2012, Calendar.NOVEMBER, 4, 01, 59, 59); Calendar testDateEndIn = new GregorianCalendar(est); testDateEndIn.set(2012, Calendar.NOVEMBER, 4, 02, 00, 00); Calendar testDateStartOut = new GregorianCalendar(est); testDateStartOut.set(2012, Calendar.MARCH, 11, 01, 59, 59); Calendar testDateStartIn = new GregorianCalendar(est); testDateStartIn.set(2012, Calendar.MARCH, 11, 02, 00, 00);
// create a Pacific Standard Time time zone SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); // set up rules for daylight savings time pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); // create a GregorianCalendar with the Pacific Daylight time zone // and the current date and time Calendar calendar = new GregorianCalendar(pdt);
SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "PST"); pdt.setStartRule(DateFields.APRIL, 1, DateFields.SUNDAY, 2*60*60*1000); pdt.setEndRule(DateFields.OCTOBER, -1, DateFields.SUNDAY, 2*60*60*1000); // Format the current time. SimpleDateFormat formatter = new SimpleDateFormat ("yyyy.mm.dd e 'at' hh:mm:ss a zzz"); Date currentTime_1 = new Date(); String dateString = formatter.format(currentTime_1); // Parse the previous string back into a Date. ParsePosition pos = new ParsePosition(0); Date currentTime_2 = formatter.parse(dateString, pos);
pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
Calendar cal; DateFormat fmt; cet.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); cet.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); cal = new GregorianCalendar(cet);
public void testDateTime_18() { SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "America/Los_Angeles"); // set up rules for daylight savings time pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); // create a GregorianCalendar with the Pacific Daylight time zone Calendar ncal = new GregorianCalendar(pdt); ncal.set(2004, 02, 21, 12, 50, 42);//before daylight savings time ncal.set(Calendar.MILLISECOND, 0); //System.err.println("cal is: "+ncal); Literal l1 = m.createTypedLiteral(ncal); assertEquals("DateTime from date", XSDDatatype.XSDdateTime, l1.getDatatype()); assertEquals("DateTime from date", XSDDateTime.class, l1.getValue().getClass()); assertEquals("DateTime from date", "2004-03-21T20:50:42Z", l1.getValue().toString()); //System.err.println("date is: "+ncal.getTime()); ncal = new GregorianCalendar(pdt); ncal.set(2004, 03, 21, 12, 50, 42);//within daylight savings time ncal.set(Calendar.MILLISECOND, 0); //System.err.println("cal is: "+ncal); l1 = m.createTypedLiteral(ncal); assertEquals("DateTime from date", XSDDatatype.XSDdateTime, l1.getDatatype()); assertEquals("DateTime from date", XSDDateTime.class, l1.getValue().getClass()); assertEquals("DateTime from date", "2004-04-21T19:50:42Z", l1.getValue().toString()); //System.err.println("date is: "+ncal.getTime()); }
public void testDateTime_18() { SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "America/Los_Angeles"); // set up rules for daylight savings time pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); // create a GregorianCalendar with the Pacific Daylight time zone Calendar ncal = new GregorianCalendar(pdt); ncal.set(2004, 02, 21, 12, 50, 42);//before daylight savings time ncal.set(Calendar.MILLISECOND, 0); //System.err.println("cal is: "+ncal); Literal l1 = m.createTypedLiteral(ncal); assertEquals("DateTime from date", XSDDatatype.XSDdateTime, l1.getDatatype()); assertEquals("DateTime from date", XSDDateTime.class, l1.getValue().getClass()); assertEquals("DateTime from date", "2004-03-21T20:50:42Z", l1.getValue().toString()); //System.err.println("date is: "+ncal.getTime()); ncal = new GregorianCalendar(pdt); ncal.set(2004, 03, 21, 12, 50, 42);//within daylight savings time ncal.set(Calendar.MILLISECOND, 0); //System.err.println("cal is: "+ncal); l1 = m.createTypedLiteral(ncal); assertEquals("DateTime from date", XSDDatatype.XSDdateTime, l1.getDatatype()); assertEquals("DateTime from date", XSDDateTime.class, l1.getValue().getClass()); assertEquals("DateTime from date", "2004-04-21T19:50:42Z", l1.getValue().toString()); //System.err.println("date is: "+ncal.getTime()); }