1 37 46 package net.sourceforge.cruisecontrol.sourcecontrols.accurev; 47 48 import org.apache.log4j.Logger; 49 50 import java.text.ParseException ; 51 import java.text.SimpleDateFormat ; 52 import java.util.Calendar ; 53 import java.util.Date ; 54 import java.util.GregorianCalendar ; 55 56 61 public class DateTimespec extends Timespec { 62 private static final Logger LOG = Logger.getLogger(DateTimespec.class); 63 private static final String DATETIME_FORMAT = "yyyy/MM/dd HH:mm:ss"; 64 67 public static final KeywordTimespec NOW = new KeywordTimespec("now"); 68 private Date date; 69 70 75 public DateTimespec(Date date) { 76 this.date = date; 77 } 78 79 86 public DateTimespec(int secondsFromNow) { 87 Calendar calendar = new GregorianCalendar (); 88 calendar.add(Calendar.SECOND, secondsFromNow); 89 this.date = calendar.getTime(); 90 } 91 92 97 public String format() { 98 if (date == null) { 99 return ""; 100 } 101 return new SimpleDateFormat (DATETIME_FORMAT).format(date); 102 } 103 104 111 public static Date parse(String date) { 112 try { 113 return new SimpleDateFormat (DATETIME_FORMAT).parse(date); 114 } catch (ParseException e) { 115 LOG.error("Error parsing date " + date + " using format" + DATETIME_FORMAT); 116 return null; 117 } 118 } 119 } 120 | Popular Tags |