2727
2828import com .cloud .utils .DateUtil .IntervalType ;
2929
30+ import org .junit .Test ;
31+
32+ import static org .junit .Assert .assertEquals ;
3033
3134public class DateUtilTest {
3235
@@ -44,17 +47,25 @@ public static void main(String[] args) {
4447 if (args .length == 2 ) {
4548 System .out .println ("Next run time: " + DateUtil .getNextRunTime (IntervalType .getIntervalType (args [0 ]), args [1 ], "GMT" , time ).toString ());
4649 }
50+ }
4751
48- time = new Date ();
52+ @ Test
53+ public void zonedTimeFormatLegacy () throws ParseException {
54+ Date time = new Date ();
4955 DateFormat dfDate = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss'Z'Z" );
5056 String str = dfDate .format (time );
51- System .out .println ("Formated TZ time string : " + str );
52- try {
53- Date dtParsed = DateUtil .parseTZDateString (str );
54- System .out .println ("Parsed TZ time string : " + dtParsed .toString ());
55- } catch (ParseException e ) {
56- System .err .println ("Parsing failed\n string : " + str + "\n exception :" + e .getLocalizedMessage ());
57- }
57+ Date dtParsed = DateUtil .parseTZDateString (str );
58+
59+ assertEquals (time .toString (), dtParsed .toString ());
5860 }
5961
62+ @ Test
63+ public void zonedTimeFormat () throws ParseException {
64+ Date time = new Date ();
65+ DateFormat dfDate = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ssZ" );
66+ String str = dfDate .format (time );
67+ Date dtParsed = DateUtil .parseTZDateString (str );
68+
69+ assertEquals (time .toString (), dtParsed .toString ());
70+ }
6071}
0 commit comments