[kepler-code] r28750 - trunk/modules/actors/src/org/kepler/date
crawl at ecoinformatics.org
crawl at ecoinformatics.org
Tue Oct 4 09:55:25 PDT 2011
Author: crawl
Date: 2011-10-04 09:55:25 -0700 (Tue, 04 Oct 2011)
New Revision: 28750
Modified:
trunk/modules/actors/src/org/kepler/date/CreateDate.java
trunk/modules/actors/src/org/kepler/date/DateToString.java
Log:
adding seconds since epoch conversion
Modified: trunk/modules/actors/src/org/kepler/date/CreateDate.java
===================================================================
--- trunk/modules/actors/src/org/kepler/date/CreateDate.java 2011-10-04 14:03:43 UTC (rev 28749)
+++ trunk/modules/actors/src/org/kepler/date/CreateDate.java 2011-10-04 16:55:25 UTC (rev 28750)
@@ -131,6 +131,9 @@
// for longs cannot handle scientific notation.
long millisec = new Double(dateStr).longValue();
outDate = new Date(millisec);
+ } else if (formatStr.equals(S_SINCE_EPOCH)) {
+ long sec = new Double(dateStr).longValue();
+ outDate = new Date(sec * 1000);
} else {
try {
SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
@@ -148,14 +151,21 @@
output.broadcast(new DateToken(outDate));
}
- // constant string for special case of seconds since epoch
- // there does not appear to be formatting symbols for this.
- public static String MS_SINCE_EPOCH = "milliseconds since epoch";
+ /** Constant string for special case of milliseconds since epoch.
+ * There does not appear to be formatting symbols for this.
+ */
+ public final static String MS_SINCE_EPOCH = "milliseconds since epoch";
+
+ /** Constant string for seconds since epoch. */
+ public final static String S_SINCE_EPOCH = "seconds since epoch";
- // common date foramts. see java.text.SimpleDateFormat.
- public static String[] dateFormats = { "MM-dd-yyyy", "MM-dd-yy",
+ /** Common date formats.
+ * @see java.text.SimpleDateFormat
+ */
+ final static String[] dateFormats = { "MM-dd-yyyy", "MM-dd-yy",
"yyyyMMdd", "yyyy.MM.dd G 'at' HH:mm:ss z", "EEE, MMM d, ''yy",
"h:mm a", "hh 'o''clock' a, zzzz", "K:mm a, z",
"yyyyy.MMMMM.dd GGG hh:mm aaa", "EEE, d MMM yyyy HH:mm:ss Z",
- "yyMMddHHmmssZ", "yyyy-MM-dd'T'HH:mm:ss.SSSZ", MS_SINCE_EPOCH };
+ "yyMMddHHmmssZ", "yyyy-MM-dd'T'HH:mm:ss.SSSZ", MS_SINCE_EPOCH,
+ S_SINCE_EPOCH };
}
\ No newline at end of file
Modified: trunk/modules/actors/src/org/kepler/date/DateToString.java
===================================================================
--- trunk/modules/actors/src/org/kepler/date/DateToString.java 2011-10-04 14:03:43 UTC (rev 28749)
+++ trunk/modules/actors/src/org/kepler/date/DateToString.java 2011-10-04 16:55:25 UTC (rev 28750)
@@ -120,6 +120,8 @@
if (formatStr.equals(CreateDate.MS_SINCE_EPOCH)) {
outStr = String.valueOf(date.getTime());
+ } else if (formatStr.equals(CreateDate.S_SINCE_EPOCH)) {
+ outStr = String.valueOf(date.getTime() / 1000);
} else {
SimpleDateFormat sdf;
More information about the Kepler-cvs
mailing list