videoInfo = client.getVideoInfo(tag);
if (StringUtils.isNotBlank(time)) {
System.out.print("Setting wayback time...");
- final String waybacktime = WayBackTimeParser.parse(time);
+ final long waybacktime = WayBackTimeParser.parse(time);
String waybackkey = client.getWayBackKey(videoInfo);
commentInfo = new CommentInfo(waybackkey, waybacktime);
}else{
public class CommentInfo {
private final String wayBackKey;
- private final String wayBackTime;
+ private final long wayBackTime;
- public CommentInfo(String wayBackKey, String wayBackTime) {
+ public CommentInfo(String wayBackKey, long wayBackTime) {
this.wayBackKey = wayBackKey;
this.wayBackTime = wayBackTime;
}
return wayBackKey;
}
- public String getWayBackTime() {
+ public long getWayBackTime() {
return wayBackTime;
}
}
* @return パース結果.
* @throws IOException パース失敗.
*/
- public static String parse(String time) throws IOException {
+ public static long parse(String time) throws IOException {
final Matcher mNumber = PATTERN_NUMBER.matcher(time);
if (mNumber.matches()) {
- return time;
+ return Long.parseLong(time);
}
final Matcher mHMS = PATTERN_YYMMDD_HH_MM_SS.matcher(time);
str.append(":");
}
final Date date = fmt.parse(str.toString());
- return Long.toString(date.getTime() / 1000);
+ return date.getTime() / 1000;
} catch (ParseException ex) {
throw new IOException("Cannot parse wayback time: " + time, ex);
}
str.append(":");
}
final Date date = fmt.parse(str.toString());
- return Long.toString(date.getTime() / 1000);
+ return date.getTime() / 1000;
} catch (ParseException ex) {
throw new IOException("Cannot parse wayback time: " + time, ex);
}
@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);
+ final long expected = 1313679612L;
+ final long 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);
+ final long expected = 1313679600L;
+ final long actual = WayBackTimeParser.parse(text);
assertEquals(expected, actual);
}
@Test
public void testParseNumber() throws IOException {
final String text = "1313679600";
- final String actual = WayBackTimeParser.parse(text);
- assertEquals(text, actual);
+ final long actual = WayBackTimeParser.parse(text);
+ assertEquals(Long.parseLong(text), actual);
}
}