Coverage Report - org.apache.commons.feedparser.tools.RFC822DateParser
 
Classes in this File Line Coverage Branch Coverage Complexity
RFC822DateParser
0%
0/5
N/A
1
 
 1  
 /*
 2  
  * Copyright 1999,2004 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.apache.commons.feedparser.tools;
 18  
 
 19  
 import java.text.SimpleDateFormat;
 20  
 import java.util.Date;
 21  
 import java.util.Locale;
 22  
 import java.util.TimeZone;
 23  
 
 24  
 /**
 25  
  *
 26  
  * RFC 822 date parsing utility.  Designed for parsing the ISO subset used in
 27  
  * Dublin Core, RSS 1.0, and Atom.
 28  
  *
 29  
  * 
 30  
  http://asg.web.cmu.edu/rfc/rfc822.html#sec-5
 31  
  * 
 32  
  5.1 SYNTAX
 33  
  * 
 34  
  * date-time   =  [ day "," ] date time        ; dd mm yy
 35  
  * ;  hh:mm:ss zzz
 36  
  * 
 37  
  * day         =  "Mon"  / "Tue" /  "Wed"  / "Thu"
 38  
  * /  "Fri"  / "Sat" /  "Sun"
 39  
  * 
 40  
  * date        =  1*2DIGIT month 2DIGIT        ; day month year
 41  
  * ;  e.g. 20 Jun 82
 42  
  * 
 43  
  * month       =  "Jan"  /  "Feb" /  "Mar"  /  "Apr"
 44  
  * /  "May"  /  "Jun" /  "Jul"  /  "Aug"
 45  
  * /  "Sep"  /  "Oct" /  "Nov"  /  "Dec"
 46  
  * 
 47  
  * time        =  hour zone                    ; ANSI and Military
 48  
  * 
 49  
  * hour        =  2DIGIT ":" 2DIGIT [":" 2DIGIT]
 50  
  * ; 00:00:00 - 23:59:59
 51  
  * 
 52  
  * zone        =  "UT"  / "GMT"                ; Universal Time
 53  
  * ; North American : UT
 54  
  * /  "EST" / "EDT"                ;  Eastern:  - 5/ - 4
 55  
  * /  "CST" / "CDT"                ;  Central:  - 6/ - 5
 56  
  * /  "MST" / "MDT"                ;  Mountain: - 7/ - 6
 57  
  * /  "PST" / "PDT"                ;  Pacific:  - 8/ - 7
 58  
  * /  1ALPHA                       ; Military: Z = UT;
 59  
  * ;  A:-1; (J not used)
 60  
  * ;  M:-12; N:+1; Y:+12
 61  
  * / ( ("+" / "-") 4DIGIT )        ; Local differential
 62  
  * ;  hours+min. (HHMM)
 63  
  * 
 64  
  5.2 SEMANTICS
 65  
  * 
 66  
  * If included, day-of-week must be the day implied by the date specification.
 67  
  * 
 68  
  * Time zone may be indicated in several ways. "UT" is Univer- sal Time
 69  
  * (formerly called "Greenwich Mean Time"); "GMT" is per- mitted as a reference
 70  
  * to Universal Time. The military standard uses a single character for each
 71  
  * zone. "Z" is Universal Time. "A" indicates one hour earlier, and "M"
 72  
  * indicates 12 hours ear- lier; "N" is one hour later, and "Y" is 12 hours
 73  
  * later. The letter "J" is not used. The other remaining two forms are taken
 74  
  * from ANSI standard X3.51-1975. One allows explicit indication of the amount
 75  
  * of offset from UT; the other uses common 3-character strings for indicating
 76  
  * time zones in North America.
 77  
  * 
 78  
  * 
 79  
  * 
 80  
  * @author <a href="mailto:burton@apache.org">Kevin A. Burton (burtonator)</a>
 81  
  * @version $Id: RFC822DateParser.java 373572 2006-01-30 19:28:41Z mvdb $
 82  
  */
 83  0
 public class RFC822DateParser {
 84  
 
 85  0
     private static SimpleDateFormat df
 86  
         = new SimpleDateFormat( "EEE, dd MMM yyyy hh:mm:ss z", Locale.ENGLISH );
 87  
 
 88  
     public static Date parse( String input ) throws java.text.ParseException {
 89  
 
 90  
         //NOTE: SimpleDateFormat uses GMT[-+]hh:mm for the TZ which breaks
 91  
         //things a bit.  Before we go on we have to repair this.
 92  
 
 93  0
         return df.parse( input );
 94  
         
 95  
     }
 96  
 
 97  
     public static String toString( Date date, TimeZone tz ) {
 98  
 
 99  0
         df.setTimeZone( tz );
 100  
 
 101  0
         return df.format( date );
 102  
         
 103  
     }
 104  
     
 105  
 }
 106