1 17 18 package org.apache.james.util; 19 20 import java.text.ParseException ; 21 import java.text.SimpleDateFormat ; 22 import java.util.Date ; 23 import java.util.Locale ; 24 import java.util.TimeZone ; 25 26 38 public class RFC822Date { 39 private static SimpleDateFormat df; 40 private static SimpleDateFormat dx; 41 private static SimpleDateFormat dy; 42 private static SimpleDateFormat dz; 43 private Date d; 44 private RFC822DateFormat rfc822Format = new RFC822DateFormat(); 45 46 static { 47 df = new SimpleDateFormat ("EE, d MMM yyyy HH:mm:ss", Locale.US); 48 dx = new SimpleDateFormat ("EE, d MMM yyyy HH:mm:ss zzzzz", Locale.US); 49 dy = new SimpleDateFormat ("EE d MMM yyyy HH:mm:ss zzzzz", Locale.US); 50 dz = new SimpleDateFormat ("d MMM yyyy HH:mm:ss zzzzz", Locale.US); 51 } 52 53 58 public RFC822Date(){ 59 d = new Date (); 60 } 61 62 67 public RFC822Date(Date da) { 68 d = da; 69 } 70 71 83 public RFC822Date(Date da, String useTZ){ 84 d = da; 85 } 86 87 94 public RFC822Date(String rfcdate) { 95 setDate(rfcdate); 96 } 97 104 public RFC822Date(String rfcdate, String useTZ) { 105 setDate(rfcdate); 106 setTimeZone(useTZ); 107 } 108 109 public void setDate(Date da){ 110 d = da; 111 } 112 113 121 public void setDate(String rfcdate) { 122 try { 123 synchronized (dx) { 124 d= dx.parse(rfcdate); 125 } 126 } catch(ParseException e) { 127 try { 128 synchronized (dz) { 129 d= dz.parse(rfcdate); 130 } 131 } catch(ParseException f) { 132 try { 133 synchronized (dy) { 134 d = dy.parse(rfcdate); 135 } 136 } catch(ParseException g) { 137 d = new Date (); 138 } 139 } 140 141 } 142 143 } 144 145 public void setTimeZone(TimeZone useTZ) { 146 rfc822Format.setTimeZone(useTZ); 147 } 148 149 public void setTimeZone(String useTZ) { 150 setTimeZone(TimeZone.getTimeZone(useTZ)); 151 } 152 153 154 158 public Date getDate() { 159 return d; 160 } 161 162 168 public String toString() { 169 return rfc822Format.format(d); 170 } 171 } 172 | Popular Tags |