import java.util.Date;
/**
- *
+ * 過去ログ取得時に指定する文字列(日付)をパースするユーティリティクラスです.
* @author yuki
*/
public final class WayBackTimeParser {
private WayBackTimeParser() {
}
+ /**
+ * 過去の時点を指定する文字列から、コメント取得フォーマットの"when"に指定する文字列へ変換します.
+ * この文字列は、1970 年 1 月 1 日 00:00:00 GMT からの秒数(一般的なミリ秒ではない)になります.
+ * @param time 時点指定文字列。"YYYY/MM/DD hh:mm:ss", "YYYY/MM/DD hh:mm", 秒数を表す数値,
+ * のいずれかであればパース可能です.
+ * @return パース結果.
+ * @throws IOException パース失敗.
+ */
public static String parse(String time) throws IOException {
Date date = null;
- String waybacktime = "0";
+ String waybacktime;
try {
final DateFormat fmt = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
date = fmt.parse(time);
--- /dev/null
+package saccubus.util;
+
+import java.io.IOException;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author yuki
+ */
+public class WayBackTimeParserTest {
+
+ /** 年月日時分秒指定 */
+ @Test
+ public void testParseYYYYMMDD_H_M_S() throws IOException {
+ final String text = "2011/08/19 00:00:12";
+ final String expected = "1313679612";
+ final String actual = WayBackTimeParser.parse(text);
+ assertEquals(expected, actual);
+ }
+
+ /** 年月日時分指定(秒省略) */
+ @Test
+ public void testParseYYYYMMDD_H_M() throws IOException {
+ final String text = "2011/08/19 00:00";
+ final String expected = "1313679600";
+ final String actual = WayBackTimeParser.parse(text);
+ assertEquals(expected, actual);
+ }
+
+ /** 1970 年 1 月 1 日 00:00:00 GMT からの秒数指定(一般的なミリ秒指定ではないことに注意 */
+ @Test
+ public void testParseNumber() throws IOException {
+ final String text = "1313679600";
+ final String actual = WayBackTimeParser.parse(text);
+ assertEquals(text, actual);
+ }
+}