@Test public void testPosixTimeZone() { if (false) { assertEquals( "PST-8PDT,M3.2.0,M11.1.0", Util.toPosix(TimeZone.getTimeZone("PST"), false)); assertEquals( "PST-8PDT1,M3.2.0/2,M11.1.0/2", Util.toPosix(TimeZone.getTimeZone("PST"), true)); } assertEquals( "JST9", Util.toPosix(TimeZone.getTimeZone("Asia/Tokyo"), true)); String posixTime = Util.toPosix(TimeZone.getTimeZone("Australia/Sydney"), true); if (posixTime.equals("EST10EST1,M10.5.0/2,M3.5.0/3")) { assertEquals("EST10EST1,M10.5.0/2,M3.5.0/3", posixTime); } else { assertEquals("EST10EST1,M10.1.0/2,M4.1.0/3", posixTime); } assertEquals( "CET1CEST1,M3.5.0/2,M10.5.0/3", Util.toPosix(TimeZone.getTimeZone("Europe/Paris"), true)); assertEquals( "UTC0", Util.toPosix(TimeZone.getTimeZone("UTC"), true)); }
public static String toPosix(TimeZone tz, boolean verbose) { StringBuilder buf = new StringBuilder(); buf.append(tz.getDisplayName(false, TimeZone.SHORT)); appendPosixTime(buf, tz.getRawOffset()); final int dstSavings = tz.getDSTSavings(); if (dstSavings == 0) { return buf.toString(); } buf.append(tz.getDisplayName(true, TimeZone.SHORT)); if (verbose || (dstSavings != 3600000)) { appendPosixTime(buf, dstSavings); } String patternString = ".*," + "startMode=([0-9]*)," + "startMonth=([0-9]*)," + "startDay=([-0-9]*)," + "startDayOfWeek=([0-9]*)," + "startTime=([0-9]*)," + "startTimeMode=([0-9]*)," + "endMode=([0-9]*)," + "endMonth=([0-9]*)," + "endDay=([-0-9]*)," + "endDayOfWeek=([0-9]*)," + "endTime=([0-9]*)," + "endTimeMode=([0-9]*).*"; Pattern pattern = Pattern.compile(patternString); String tzString = tz.toString(); Matcher matcher = pattern.matcher(tzString); if (!matcher.matches()) { throw new AssertionError("tz.toString not of expected format: " + tzString); } int j = 0; int startMode = Integer.valueOf(matcher.group(++j)); int startMonth = Integer.valueOf(matcher.group(++j)); int startDay = Integer.valueOf(matcher.group(++j)); int startDayOfWeek = Integer.valueOf(matcher.group(++j)); int startTime = Integer.valueOf(matcher.group(++j)); int startTimeMode = Integer.valueOf(matcher.group(++j)); int endMode = Integer.valueOf(matcher.group(++j)); int endMonth = Integer.valueOf(matcher.group(++j)); int endDay = Integer.valueOf(matcher.group(++j)); int endDayOfWeek = Integer.valueOf(matcher.group(++j)); int endTime = Integer.valueOf(matcher.group(++j)); int endTimeMode = Integer.valueOf(matcher.group(++j)); appendPosixDaylightTransition( tz, buf, startMode, startDay, startMonth, startDayOfWeek, startTime, startTimeMode, verbose, false); appendPosixDaylightTransition( tz, buf, endMode, endDay, endMonth, endDayOfWeek, endTime, endTimeMode, verbose, true); return buf.toString(); }
Util { public static String toPosix(TimeZone tz, boolean verbose) { StringBuilder buf = new StringBuilder(); buf.append(tz.getDisplayName(false, TimeZone.SHORT)); appendPosixTime(buf, tz.getRawOffset()); final int dstSavings = tz.getDSTSavings(); if (dstSavings == 0) { return buf.toString(); } buf.append(tz.getDisplayName(true, TimeZone.SHORT)); if (verbose || (dstSavings != 3600000)) { appendPosixTime(buf, dstSavings); } String patternString = ".*," + "startMode=([0-9]*)," + "startMonth=([0-9]*)," + "startDay=([-0-9]*)," + "startDayOfWeek=([0-9]*)," + "startTime=([0-9]*)," + "startTimeMode=([0-9]*)," + "endMode=([0-9]*)," + "endMonth=([0-9]*)," + "endDay=([-0-9]*)," + "endDayOfWeek=([0-9]*)," + "endTime=([0-9]*)," + "endTimeMode=([0-9]*).*"; Pattern pattern = Pattern.compile(patternString); String tzString = tz.toString(); Matcher matcher = pattern.matcher(tzString); if (!matcher.matches()) { throw new AssertionError("tz.toString not of expected format: " + tzString); } int j = 0; int startMode = Integer.valueOf(matcher.group(++j)); int startMonth = Integer.valueOf(matcher.group(++j)); int startDay = Integer.valueOf(matcher.group(++j)); int startDayOfWeek = Integer.valueOf(matcher.group(++j)); int startTime = Integer.valueOf(matcher.group(++j)); int startTimeMode = Integer.valueOf(matcher.group(++j)); int endMode = Integer.valueOf(matcher.group(++j)); int endMonth = Integer.valueOf(matcher.group(++j)); int endDay = Integer.valueOf(matcher.group(++j)); int endDayOfWeek = Integer.valueOf(matcher.group(++j)); int endTime = Integer.valueOf(matcher.group(++j)); int endTimeMode = Integer.valueOf(matcher.group(++j)); appendPosixDaylightTransition( tz, buf, startMode, startDay, startMonth, startDayOfWeek, startTime, startTimeMode, verbose, false); appendPosixDaylightTransition( tz, buf, endMode, endDay, endMonth, endDayOfWeek, endTime, endTimeMode, verbose, true); return buf.toString(); } }
Util { public static String toPosix(TimeZone tz, boolean verbose) { StringBuilder buf = new StringBuilder(); buf.append(tz.getDisplayName(false, TimeZone.SHORT)); appendPosixTime(buf, tz.getRawOffset()); final int dstSavings = tz.getDSTSavings(); if (dstSavings == 0) { return buf.toString(); } buf.append(tz.getDisplayName(true, TimeZone.SHORT)); if (verbose || (dstSavings != 3600000)) { appendPosixTime(buf, dstSavings); } String patternString = ".*," + "startMode=([0-9]*)," + "startMonth=([0-9]*)," + "startDay=([-0-9]*)," + "startDayOfWeek=([0-9]*)," + "startTime=([0-9]*)," + "startTimeMode=([0-9]*)," + "endMode=([0-9]*)," + "endMonth=([0-9]*)," + "endDay=([-0-9]*)," + "endDayOfWeek=([0-9]*)," + "endTime=([0-9]*)," + "endTimeMode=([0-9]*).*"; Pattern pattern = Pattern.compile(patternString); String tzString = tz.toString(); Matcher matcher = pattern.matcher(tzString); if (!matcher.matches()) { throw new AssertionError("tz.toString not of expected format: " + tzString); } int j = 0; int startMode = Integer.valueOf(matcher.group(++j)); int startMonth = Integer.valueOf(matcher.group(++j)); int startDay = Integer.valueOf(matcher.group(++j)); int startDayOfWeek = Integer.valueOf(matcher.group(++j)); int startTime = Integer.valueOf(matcher.group(++j)); int startTimeMode = Integer.valueOf(matcher.group(++j)); int endMode = Integer.valueOf(matcher.group(++j)); int endMonth = Integer.valueOf(matcher.group(++j)); int endDay = Integer.valueOf(matcher.group(++j)); int endDayOfWeek = Integer.valueOf(matcher.group(++j)); int endTime = Integer.valueOf(matcher.group(++j)); int endTimeMode = Integer.valueOf(matcher.group(++j)); appendPosixDaylightTransition( tz, buf, startMode, startDay, startMonth, startDayOfWeek, startTime, startTimeMode, verbose, false); appendPosixDaylightTransition( tz, buf, endMode, endDay, endMonth, endDayOfWeek, endTime, endTimeMode, verbose, true); return buf.toString(); } private  Util(); }
Util { public static String toPosix(TimeZone tz, boolean verbose) { StringBuilder buf = new StringBuilder(); buf.append(tz.getDisplayName(false, TimeZone.SHORT)); appendPosixTime(buf, tz.getRawOffset()); final int dstSavings = tz.getDSTSavings(); if (dstSavings == 0) { return buf.toString(); } buf.append(tz.getDisplayName(true, TimeZone.SHORT)); if (verbose || (dstSavings != 3600000)) { appendPosixTime(buf, dstSavings); } String patternString = ".*," + "startMode=([0-9]*)," + "startMonth=([0-9]*)," + "startDay=([-0-9]*)," + "startDayOfWeek=([0-9]*)," + "startTime=([0-9]*)," + "startTimeMode=([0-9]*)," + "endMode=([0-9]*)," + "endMonth=([0-9]*)," + "endDay=([-0-9]*)," + "endDayOfWeek=([0-9]*)," + "endTime=([0-9]*)," + "endTimeMode=([0-9]*).*"; Pattern pattern = Pattern.compile(patternString); String tzString = tz.toString(); Matcher matcher = pattern.matcher(tzString); if (!matcher.matches()) { throw new AssertionError("tz.toString not of expected format: " + tzString); } int j = 0; int startMode = Integer.valueOf(matcher.group(++j)); int startMonth = Integer.valueOf(matcher.group(++j)); int startDay = Integer.valueOf(matcher.group(++j)); int startDayOfWeek = Integer.valueOf(matcher.group(++j)); int startTime = Integer.valueOf(matcher.group(++j)); int startTimeMode = Integer.valueOf(matcher.group(++j)); int endMode = Integer.valueOf(matcher.group(++j)); int endMonth = Integer.valueOf(matcher.group(++j)); int endDay = Integer.valueOf(matcher.group(++j)); int endDayOfWeek = Integer.valueOf(matcher.group(++j)); int endTime = Integer.valueOf(matcher.group(++j)); int endTimeMode = Integer.valueOf(matcher.group(++j)); appendPosixDaylightTransition( tz, buf, startMode, startDay, startMonth, startDayOfWeek, startTime, startTimeMode, verbose, false); appendPosixDaylightTransition( tz, buf, endMode, endDay, endMonth, endDayOfWeek, endTime, endTimeMode, verbose, true); return buf.toString(); } private  Util(); static void discard(Object o); static void discard(int i); static boolean discard(boolean b); static void discard(double d); static void swallow(
      Throwable e,
      Logger logger); static boolean equal(
      Object s0,
      Object s1); static boolean equalShallow(
      List<? extends T> list0, List<? extends T> list1); static int hash(
      int i,
      int j); static int hash(
      int h,
      Object o); static int hashArray(
      int h,
      Object[] a); static int hashV(Object... a); static int hashCode(double v); static Set<T> minus(Set<T> set1, Set<T> set2); static double nLogN(double d); static void print(
      PrintWriter pw,
      Object o); static void print(
      PrintWriter pw,
      Object o,
      int indent); static void printJavaString(
      PrintWriter pw,
      String s,
      boolean nullMeansNull); static void println(
      PrintWriter pw,
      Object o); static String toScientificNotation(BigDecimal bd); static String replace(
      String s,
      String find,
      String replace); static URL toURL(File file); static String getFileTimestamp(); static String stripDoubleQuotes(String value); static String toJavaId(
      String s,
      int ordinal); static String toLinux(String s); static List<T> toList(Iterator<T> iter); static boolean isNullOrEmpty(String s); static String commaList(List<T> list); static String sepList(List<T> list, String sep); static Charset getDefaultCharset(); static Error newInternal(); static Error newInternal(String s); static Error newInternal(Throwable e); static Error newInternal(Throwable e, String s); static String getMessages(Throwable t); static String getStackTrace(Throwable t); static void pre(boolean b, String description); static void post(boolean b, String description); static void permAssert(boolean b, String description); static RuntimeException needToImplement(Object o); static T deprecated(T argument, boolean fail); static void loadLibrary(String libName); static boolean contains(
      String[] a,
      int length,
      String s); static String readAllAsString(Reader reader); static void squelchJar(JarFile jar); static void squelchStream(InputStream stream); static void squelchStream(OutputStream stream); static void squelchReader(Reader reader); static void squelchWriter(Writer writer); static void squelchStmt(Statement stmt); static void squelchConnection(Connection connection); static String rtrim(String s); static String rpad(String s, int len); static String toString(
      Iterable<T> iterable, String start, String sep, String end); static String toPosix(TimeZone tz, boolean verbose); static Locale parseLocale(String localeString); static int runApplication(
      String[] cmdarray,
      Logger logger,
      Reader appInput,
      Writer appOutput); static ProcessBuilder newAppProcess(String[] cmdarray); static int runAppProcess(
      ProcessBuilder pb,
      Logger logger,
      Reader appInput,
      Writer appOutput); static List<E> cast(List<? super E> list, Class<E> clazz); static Iterator<E> cast(
      final Iterator<?> iter,
      final Class<E> clazz); static Iterable<E> cast(
      final Iterable<? super E> iterable,
      final Class<E> clazz); static Iterable<E> filter(
      final Iterable<? extends Object> iterable,
      final Class<E> includeFilter); static Collection<E> filter(
      final Collection<?> collection,
      final Class<E> includeFilter); static List<E> filter(
      final List<?> list,
      final Class<E> includeFilter); static Map<String, String> toMap(
      final Properties properties); static Map<K, V> mapOf(K key, V value, Object... keyValues); static Error unexpected(E value); static Map<String, T> enumConstants(
      Class<T> clazz); @SuppressWarnings({"unchecked" }) static synchronized T enumVal(
      Class<T> clazz,
      String name); static List<E> quotientList(
      final List<E> list, final int n, final int k); static T first(T t0, T t1); static Iterable<T> orEmpty(Iterable<T> t0); static E last(List<E> list); static List<E> skipLast(List<E> list); static List<E> skipLast(List<E> list, int n); static List<E> last(List<E> list, int n); static List<E> skip(List<E> list); static List<E> skip(List<E> list, int fromIndex); static List<Integer> range(final int start, final int end); static String toCamelCase(String name); static String camelToUpper(String name); static boolean isDistinct(List<E> list); static int firstDuplicate(List<E> list); static int match2(List<String> strings, String name,
      boolean caseSensitive1); static boolean match(boolean caseSensitive, String name1,
      String name0); static boolean startsWith(List<E> list0, List<E> list1); }
Util { public static String toPosix(TimeZone tz, boolean verbose) { StringBuilder buf = new StringBuilder(); buf.append(tz.getDisplayName(false, TimeZone.SHORT)); appendPosixTime(buf, tz.getRawOffset()); final int dstSavings = tz.getDSTSavings(); if (dstSavings == 0) { return buf.toString(); } buf.append(tz.getDisplayName(true, TimeZone.SHORT)); if (verbose || (dstSavings != 3600000)) { appendPosixTime(buf, dstSavings); } String patternString = ".*," + "startMode=([0-9]*)," + "startMonth=([0-9]*)," + "startDay=([-0-9]*)," + "startDayOfWeek=([0-9]*)," + "startTime=([0-9]*)," + "startTimeMode=([0-9]*)," + "endMode=([0-9]*)," + "endMonth=([0-9]*)," + "endDay=([-0-9]*)," + "endDayOfWeek=([0-9]*)," + "endTime=([0-9]*)," + "endTimeMode=([0-9]*).*"; Pattern pattern = Pattern.compile(patternString); String tzString = tz.toString(); Matcher matcher = pattern.matcher(tzString); if (!matcher.matches()) { throw new AssertionError("tz.toString not of expected format: " + tzString); } int j = 0; int startMode = Integer.valueOf(matcher.group(++j)); int startMonth = Integer.valueOf(matcher.group(++j)); int startDay = Integer.valueOf(matcher.group(++j)); int startDayOfWeek = Integer.valueOf(matcher.group(++j)); int startTime = Integer.valueOf(matcher.group(++j)); int startTimeMode = Integer.valueOf(matcher.group(++j)); int endMode = Integer.valueOf(matcher.group(++j)); int endMonth = Integer.valueOf(matcher.group(++j)); int endDay = Integer.valueOf(matcher.group(++j)); int endDayOfWeek = Integer.valueOf(matcher.group(++j)); int endTime = Integer.valueOf(matcher.group(++j)); int endTimeMode = Integer.valueOf(matcher.group(++j)); appendPosixDaylightTransition( tz, buf, startMode, startDay, startMonth, startDayOfWeek, startTime, startTimeMode, verbose, false); appendPosixDaylightTransition( tz, buf, endMode, endDay, endMonth, endDayOfWeek, endTime, endTimeMode, verbose, true); return buf.toString(); } private  Util(); static void discard(Object o); static void discard(int i); static boolean discard(boolean b); static void discard(double d); static void swallow(
      Throwable e,
      Logger logger); static boolean equal(
      Object s0,
      Object s1); static boolean equalShallow(
      List<? extends T> list0, List<? extends T> list1); static int hash(
      int i,
      int j); static int hash(
      int h,
      Object o); static int hashArray(
      int h,
      Object[] a); static int hashV(Object... a); static int hashCode(double v); static Set<T> minus(Set<T> set1, Set<T> set2); static double nLogN(double d); static void print(
      PrintWriter pw,
      Object o); static void print(
      PrintWriter pw,
      Object o,
      int indent); static void printJavaString(
      PrintWriter pw,
      String s,
      boolean nullMeansNull); static void println(
      PrintWriter pw,
      Object o); static String toScientificNotation(BigDecimal bd); static String replace(
      String s,
      String find,
      String replace); static URL toURL(File file); static String getFileTimestamp(); static String stripDoubleQuotes(String value); static String toJavaId(
      String s,
      int ordinal); static String toLinux(String s); static List<T> toList(Iterator<T> iter); static boolean isNullOrEmpty(String s); static String commaList(List<T> list); static String sepList(List<T> list, String sep); static Charset getDefaultCharset(); static Error newInternal(); static Error newInternal(String s); static Error newInternal(Throwable e); static Error newInternal(Throwable e, String s); static String getMessages(Throwable t); static String getStackTrace(Throwable t); static void pre(boolean b, String description); static void post(boolean b, String description); static void permAssert(boolean b, String description); static RuntimeException needToImplement(Object o); static T deprecated(T argument, boolean fail); static void loadLibrary(String libName); static boolean contains(
      String[] a,
      int length,
      String s); static String readAllAsString(Reader reader); static void squelchJar(JarFile jar); static void squelchStream(InputStream stream); static void squelchStream(OutputStream stream); static void squelchReader(Reader reader); static void squelchWriter(Writer writer); static void squelchStmt(Statement stmt); static void squelchConnection(Connection connection); static String rtrim(String s); static String rpad(String s, int len); static String toString(
      Iterable<T> iterable, String start, String sep, String end); static String toPosix(TimeZone tz, boolean verbose); static Locale parseLocale(String localeString); static int runApplication(
      String[] cmdarray,
      Logger logger,
      Reader appInput,
      Writer appOutput); static ProcessBuilder newAppProcess(String[] cmdarray); static int runAppProcess(
      ProcessBuilder pb,
      Logger logger,
      Reader appInput,
      Writer appOutput); static List<E> cast(List<? super E> list, Class<E> clazz); static Iterator<E> cast(
      final Iterator<?> iter,
      final Class<E> clazz); static Iterable<E> cast(
      final Iterable<? super E> iterable,
      final Class<E> clazz); static Iterable<E> filter(
      final Iterable<? extends Object> iterable,
      final Class<E> includeFilter); static Collection<E> filter(
      final Collection<?> collection,
      final Class<E> includeFilter); static List<E> filter(
      final List<?> list,
      final Class<E> includeFilter); static Map<String, String> toMap(
      final Properties properties); static Map<K, V> mapOf(K key, V value, Object... keyValues); static Error unexpected(E value); static Map<String, T> enumConstants(
      Class<T> clazz); @SuppressWarnings({"unchecked" }) static synchronized T enumVal(
      Class<T> clazz,
      String name); static List<E> quotientList(
      final List<E> list, final int n, final int k); static T first(T t0, T t1); static Iterable<T> orEmpty(Iterable<T> t0); static E last(List<E> list); static List<E> skipLast(List<E> list); static List<E> skipLast(List<E> list, int n); static List<E> last(List<E> list, int n); static List<E> skip(List<E> list); static List<E> skip(List<E> list, int fromIndex); static List<Integer> range(final int start, final int end); static String toCamelCase(String name); static String camelToUpper(String name); static boolean isDistinct(List<E> list); static int firstDuplicate(List<E> list); static int match2(List<String> strings, String name,
      boolean caseSensitive1); static boolean match(boolean caseSensitive, String name1,
      String name0); static boolean startsWith(List<E> list0, List<E> list1); static final String AWT_WORKAROUND_PROPERTY; static final String LINE_SEPARATOR; static final String FILE_SEPARATOR; static final String FILE_TIMESTAMP_FORMAT; }