1/****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one   *
3 * or more contributor license agreements.  See the NOTICE file *
4 * distributed with this work for additional information        *
5 * regarding copyright ownership.  The ASF licenses this file   *
6 * to you under the Apache License, Version 2.0 (the            *
7 * "License"); you may not use this file except in compliance   *
8 * with the License.  You may obtain a copy of the License at   *
9 *                                                              *
10 *   http://www.apache.org/licenses/LICENSE-2.0                 *
11 *                                                              *
12 * Unless required by applicable law or agreed to in writing,   *
13 * software distributed under the License is distributed on an  *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15 * KIND, either express or implied.  See the License for the    *
16 * specific language governing permissions and limitations      *
17 * under the License.                                           *
18 ****************************************************************/
19
20package org.apache.james.mime4j.field;
21
22//BEGIN android-changed: Stubbing out logging
23
24import com.android.mail.utils.LogUtils;
25
26import org.apache.james.mime4j.Log;
27import org.apache.james.mime4j.LogFactory;
28//END
29import org.apache.james.mime4j.field.datetime.DateTime;
30import org.apache.james.mime4j.field.datetime.parser.ParseException;
31
32import java.util.Date;
33
34public class DateTimeField extends Field {
35    private Date date;
36    private ParseException parseException;
37
38    protected DateTimeField(String name, String body, String raw, Date date, ParseException parseException) {
39        super(name, body, raw);
40        this.date = date;
41        this.parseException = parseException;
42    }
43
44    public Date getDate() {
45        return date;
46    }
47
48    public ParseException getParseException() {
49        return parseException;
50    }
51
52    public static class Parser implements FieldParser {
53        private static Log log = LogFactory.getLog(Parser.class);
54
55        public Field parse(final String name, String body, final String raw) {
56            Date date = null;
57            ParseException parseException = null;
58            //BEGIN android-changed
59            body = LogUtils.cleanUpMimeDate(body);
60            //END android-changed
61            try {
62                date = DateTime.parse(body).getDate();
63            }
64            catch (ParseException e) {
65                if (log.isDebugEnabled()) {
66                    log.debug("Parsing value '" + body + "': "+ e.getMessage());
67                }
68                parseException = e;
69            }
70            return new DateTimeField(name, body, raw, date, parseException);
71        }
72    }
73}
74