import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.DateInterval;
import com.ibm.icu.util.Output;
+import com.ibm.icu.util.TimeZone;
import com.ibm.icu.util.ULocale;
import com.ibm.icu.util.ULocale.Category;
}
}
+ /**
+ * Get the TimeZone
+ * @return A copy of the TimeZone associated with this date interval formatter.
+ * @draft ICU 53
+ */
+ public TimeZone getTimeZone()
+ {
+ if ( fDateFormat != null ) {
+ // Here we clone, like other getters here, but unlike
+ // DateFormat.getTimeZone() and Calendar.getTimeZone()
+ // which return the TimeZone from the Calendar's zone variable
+ return (TimeZone)(fDateFormat.getTimeZone().clone());
+ }
+ // If fDateFormat is null (unexpected), return default timezone.
+ return TimeZone.getDefault();
+ }
+
+
+ /**
+ * Set the TimeZone for the calendar used by this DateIntervalFormat object.
+ * @param zone The new TimeZone to use.
+ * @draft ICU 53
+ */
+ public void setTimeZone(TimeZone zone)
+ {
+ if (fDateFormat != null) {
+ fDateFormat.setTimeZone(zone);
+ }
+ // fDateFormat has the master calendar for the DateIntervalFormat;
+ // fFromCalendar and fToCalendar are internal work clones of that calendar.
+ if (fFromCalendar != null) {
+ fFromCalendar.setTimeZone(zone);
+ }
+ if (fToCalendar != null) {
+ fToCalendar.setTimeZone(zone);
+ }
+ }
/**
* Gets the date formatter
/*
*******************************************************************************
- * Copyright (C) 2001-2013, International Business Machines Corporation and *
+ * Copyright (C) 2001-2014, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
import com.ibm.icu.text.SimpleDateFormat;
import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.DateInterval;
+import com.ibm.icu.util.TimeZone;
import com.ibm.icu.util.ULocale;
public class DateIntervalFormatTest extends com.ibm.icu.dev.test.TestFmwk {
actualPattern);
}
+ public void TestGetSetTimeZone(){
+ DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance("MMMdHHmm", Locale.ENGLISH);
+ long date1 = 1299090600000L; // 2011-Mar-02 1030 in US/Pacific, 2011-Mar-03 0330 in Asia/Tokyo
+ long date2 = 1299115800000L; // 2011-Mar-02 1730 in US/Pacific, 2011-Mar-03 1030 in Asia/Tokyo
+ DateInterval dtitv = new DateInterval(date1, date2);
+ TimeZone tzCalif = TimeZone.getFrozenTimeZone("US/Pacific");
+ TimeZone tzTokyo = TimeZone.getFrozenTimeZone("Asia/Tokyo");
+ String fmtCalif = "Mar 2, 10:30 \u2013 Mar 2, 17:30"; // ICU4C result is "Mar 2, 10:30 \u2013 17:30" (does not duplicate day)
+ String fmtTokyo = "Mar 3, 03:30 \u2013 Mar 3, 10:30"; // ICU4C result is "Mar 3, 03:30 \u2013 10:30" (does not duplicate day)
+
+ StringBuffer buf = new StringBuffer();
+ FieldPosition pos = new FieldPosition(0);
+ dtitvfmt.setTimeZone(tzCalif);
+ dtitvfmt.format(dtitv, buf, pos);
+ if (!buf.toString().equals(fmtCalif)) {
+ errln("DateIntervalFormat for tzCalif, expect \"" + fmtCalif + "\", get \"" + buf + "\"");
+ }
+
+ buf.setLength(0);
+ pos.setBeginIndex(0);
+ dtitvfmt.setTimeZone(tzTokyo);
+ dtitvfmt.format(dtitv, buf, pos);
+ if (!buf.toString().equals(fmtTokyo)) {
+ errln("DateIntervalFormat for tzTokyo, expect \"" + fmtTokyo + "\", get \"" + buf + "\"");
+ }
+
+ if (!dtitvfmt.getTimeZone().equals(tzTokyo)) {
+ errln("DateIntervalFormat.getTimeZone() returns mismatch");
+ }
+ }
+
+
/* Tests the method
* public int hashCode()
*/