001package votorola.g.text; // Copyright 2009, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. 002 003import votorola.g.lang.*; 004 005 006/** SimpleDateFormat utilities. 007 */ 008public @ThreadSafe final class SimpleDateFormatX 009{ 010 011 private SimpleDateFormatX() {} 012 013 014 015 /** An ISO 8601 format pattern for local times. 016 * 017 * @see <a href='http://en.wikipedia.org/wiki/ISO_8601' 018 * >http://en.wikipedia.org/wiki/ISO_8601</a> 019 */ 020 public static final String ISO_8601_LOCAL_PATTERN = "yyyy-MM-dd'T'HH:mm:ss"; 021 022 023 024 /** An ISO 8601 format pattern (wrong). When parsing a value in timezone Z (GMT), the 025 * input needs to be {@linkplain #simplifiedISO8601(String) dumbed down}. In a "GMT" 026 * timezone, the output probably needs <a 027 * href='http://www.fileformat.info/tip/java/simpledateformat.htm'>correcting</a>. 028 * 029 * <p>This is wrong because it uses a named timezone.</p> 030 * 031 * @see <a href='http://en.wikipedia.org/wiki/ISO_8601' 032 * >http://en.wikipedia.org/wiki/ISO_8601</a> 033 */ 034 public static final String ISO_8601_PATTERN = "yyyy-MM-dd'T'HH:mm:ssz"; 035 036 037 038 /** An ISO 8601 format pattern (corrected). 039 * 040 * @see <a href='http://en.wikipedia.org/wiki/ISO_8601' 041 * >http://en.wikipedia.org/wiki/ISO_8601</a> 042 */ 043 public static final String ISO_8601_PATTERN_C = "yyyy-MM-dd'T'HH:mm:ssZ"; 044 045 046 047 /** Simplifies an ISO 8601 format string, for parsing against {@linkplain 048 * #ISO_8601_PATTERN ISO_8601_PATTERN}. 049 */ 050 public static String simplifiedISO8601( String s ) 051 { 052 if( s.charAt(19) == 'Z' && s.length() == 20 ) s = s.substring(0,19) + "GMT"; // it cannot parse the Z, so help it out 053 054 return s; 055 } 056 057 058 059}