Coverage Report - org.webslinger.io.HttpUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
HttpUtil
40%
6/15
0%
0/3
0
 
 1  
 package org.webslinger.io;
 2  
 
 3  
 import java.text.DateFormat;
 4  
 import java.text.ParseException;
 5  
 import java.text.SimpleDateFormat;
 6  
 import java.util.Date;
 7  
 import java.util.Locale;
 8  
 import java.util.TimeZone;
 9  
 
 10  0
 public final class HttpUtil {
 11  1
     public static final SimpleDateFormat dateFormats[] = {
 12  
         new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
 13  
         new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
 14  
         new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US)
 15  
     };
 16  1
     public static final TimeZone gmt = TimeZone.getTimeZone("GMT");
 17  
     static {
 18  4
         for (SimpleDateFormat format: dateFormats) {
 19  3
             format.setTimeZone(gmt);
 20  
         }
 21  1
     }
 22  
 
 23  
     public static final Date parseDate(String value) {
 24  0
         if (value == null) return null;
 25  0
         for (SimpleDateFormat format: dateFormats) {
 26  
             try {
 27  0
                 return format.parse(value);
 28  0
             } catch (ParseException e) {
 29  
             }
 30  
         }
 31  0
         return null;
 32  
     }
 33  
 
 34  
     public static final long getDateMilliseconds(String value) {
 35  0
         Date date = parseDate(value);
 36  0
         if (date == null) return 0;
 37  0
         return date.getTime();
 38  
     }
 39  
 
 40  
     public static final String formatDate(long time) {
 41  83
         return dateFormats[0].format(new Long(time));
 42  
     }
 43  
 }