1 17 18 package org.apache.james.util; 19 20 import java.text.DateFormat ; 21 import java.text.ParseException ; 22 import java.text.SimpleDateFormat ; 23 import java.util.Date ; 24 import java.util.Locale ; 25 import java.util.TimeZone ; 26 27 32 public class RFC977DateFormat implements SimplifiedDateFormat { 33 34 37 private final SynchronizedDateFormat internalLongDateFormat; 38 39 42 private final SynchronizedDateFormat internalShortDateFormat; 43 44 47 public RFC977DateFormat() { 48 internalLongDateFormat = new SynchronizedDateFormat("yyyyMMdd HHmmss", Locale.ENGLISH); 49 internalShortDateFormat = new SynchronizedDateFormat("yyMMdd HHmmss", Locale.ENGLISH); 50 } 51 52 58 public String format(Date d) { 59 return internalLongDateFormat.format(d); 60 } 61 62 74 public Date parse(String source) throws ParseException { 75 source = source.trim(); 76 if (source.indexOf(' ') == 6) { 77 return internalShortDateFormat.parse(source); 78 } else { 79 return internalLongDateFormat.parse(source); 80 } 81 } 82 83 87 public void setTimeZone(TimeZone zone) { 88 synchronized(this) { 89 internalShortDateFormat.setTimeZone(zone); 90 internalLongDateFormat.setTimeZone(zone); 91 } 92 } 93 94 98 public TimeZone getTimeZone() { 99 synchronized(this) { 100 return internalShortDateFormat.getTimeZone(); 101 } 102 } 103 104 112 public void setLenient(boolean lenient) 113 { 114 synchronized(this) { 115 internalShortDateFormat.setLenient(lenient); 116 internalLongDateFormat.setLenient(lenient); 117 } 118 } 119 120 124 public boolean isLenient() 125 { 126 synchronized(this) { 127 return internalShortDateFormat.isLenient(); 128 } 129 } 130 131 132 135 public boolean equals(Object obj) { 136 if (this == obj) { 137 return true; 138 } 139 if (!(obj instanceof RFC977DateFormat)) { 140 return false; 141 } 142 RFC977DateFormat theOtherRFC977DateFormat = (RFC977DateFormat)obj; 143 synchronized (this) { 144 return ((internalShortDateFormat.equals(theOtherRFC977DateFormat.internalShortDateFormat)) && 145 (internalLongDateFormat.equals(theOtherRFC977DateFormat.internalLongDateFormat))); 146 } 147 } 148 149 152 public int hashCode() { 153 return (int)(internalLongDateFormat.hashCode() & internalShortDateFormat.hashCode()); 154 } 155 156 } 157 | Popular Tags |