001/** 002 * Copyright 2011 Bill Brown 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.colorfulsoftware.rss; 017 018import java.io.Serializable; 019import java.util.Date; 020 021/** 022 * <p> 023 * The <pubDate> element. 024 * </p> 025 * <p> 026 * From the <a href="http://cyber.law.harvard.edu/rss/rss.html">RSS 2.0 027 * specification</a>... 028 * </p> 029 * <p> 030 * For Channel: The publication date for the content in the channel. For 031 * example, the New York Times publishes on a daily basis, the publication date 032 * flips once every 24 hours. That's when the pubDate of the channel changes. 033 * All date-times in RSS conform to the Date and Time Specification of <a 034 * href="http://asg.web.cmu.edu/rfc/rfc822.html">RFC 822</a>, with the exception 035 * that the year may be expressed with two characters or four characters (four 036 * preferred). 037 * </p> 038 * 039 * <p> 040 * For Item: Indicates when the item was published. <a href= 041 * "http://cyber.law.harvard.edu/rss/rss.html#ltpubdategtSubelementOfLtitemgt" 042 * >More</a>. 043 * </p> 044 * 045 * <p> 046 * <pubDate> is an optional sub-element of <item>. 047 * </p> 048 * 049 * <p> 050 * Its value is a <a href="http://asg.web.cmu.edu/rfc/rfc822.html">date</a>, 051 * indicating when the item was published. If it's a date in the future, 052 * aggregators may choose to not display the item until that date. 053 * </p> 054 * 055 * <p> 056 * <pubDate>Sun, 19 May 2002 15:21:36 GMT</pubDate> 057 * </p> 058 * 059 * @author Bill Brown 060 * 061 */ 062public class PubDate implements Serializable { 063 064 /** 065 * 066 */ 067 private static final long serialVersionUID = -1876136443511726976L; 068 069 private final RSSDateConstruct pubDate; 070 071 PubDate(String pubDate) throws RSSpectException { 072 this.pubDate = new RSSDateConstruct(pubDate); 073 } 074 075 PubDate(Date pubDate) { 076 this.pubDate = new RSSDateConstruct(pubDate); 077 } 078 079 /** 080 * 081 * @return the date timestamp for this element. 082 */ 083 public Date getDateTime() { 084 return pubDate.getDateTime(); 085 } 086 087 /** 088 * 089 * @return the string formated version of the time for example 090 * 2006-04-28T12:50:43.337-05:00 091 */ 092 public String getText() { 093 return pubDate.getText(); 094 } 095 096 /** 097 * Shows the contents of the <pubDate> element. 098 */ 099 @Override 100 public String toString() { 101 return "<pubDate>" + pubDate + "</pubDate>"; 102 } 103 104 @Override 105 public boolean equals(Object obj) { 106 if (obj == this) { 107 return true; 108 } 109 if (!(obj instanceof PubDate)) { 110 return false; 111 } 112 return this.toString().equals(obj.toString()); 113 } 114 115 @Override public int hashCode() { 116 return toString().hashCode(); 117 } 118}