1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.geronimo.javamail.store.imap.connection;
19
20 import java.text.FieldPosition;
21 import java.text.NumberFormat;
22 import java.text.ParsePosition;
23 import java.text.SimpleDateFormat;
24 import java.util.Calendar;
25 import java.util.Date;
26 import java.util.Locale;
27
28 /**
29 * Formats ths date as specified by
30 * draft-ietf-drums-msg-fmt-08 dated January 26, 2000
31 * which supercedes RFC822.
32 * <p/>
33 * <p/>
34 * The format used is <code>EEE, d MMM yyyy HH:mm:ss Z</code> and
35 * locale is always US-ASCII.
36 *
37 * @version $Rev: 594520 $ $Date: 2007-11-13 07:57:39 -0500 (Tue, 13 Nov 2007) $
38 */
39 public class IMAPDateFormat extends SimpleDateFormat {
40 public IMAPDateFormat() {
41 super("dd-MMM-yyyy HH:mm:ss Z", Locale.US);
42 }
43 public StringBuffer format(Date date, StringBuffer buffer, FieldPosition position) {
44 StringBuffer result = super.format(date, buffer, position);
45 // The RFC 2060 requires that the day in the date be formatted with either 2 digits
46 // or one digit. Our format specifies 2 digits, which pads with leading
47 // zeros. We need to check for this and whack it if it's there
48 if (result.charAt(0) == '0') {
49 result.deleteCharAt(0);
50 }
51 return result;
52 }
53
54 /**
55 * The calendar cannot be set
56 * @param calendar
57 * @throws UnsupportedOperationException
58 */
59 public void setCalendar(Calendar calendar) {
60 throw new UnsupportedOperationException();
61 }
62
63 /**
64 * The format cannot be set
65 * @param format
66 * @throws UnsupportedOperationException
67 */
68 public void setNumberFormat(NumberFormat format) {
69 throw new UnsupportedOperationException();
70 }
71 }
72