Permalink
Browse files

Added isoParse and isBefore now date function in jspringbot-date

  • Loading branch information...
1 parent 1c83cd7 commit 1ed0bc11d3d48429d42426bcb747fb394657616e @badong2210 badong2210 committed Mar 18, 2013
@@ -22,6 +22,7 @@
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.ISODateTimeFormat;
import org.jspringbot.syntax.HighlightRobotLogger;
import java.sql.Time;
@@ -117,6 +118,17 @@ public String parseDateTime(String dateStr, String pattern) {
return formatDateTime();
}
+ public String isoParseDateTime(String dateStr) {
+ LOG.keywordAppender()
+ .appendProperty("Date String", dateStr);
+
+ DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
+ current = fmt.parseDateTime(dateStr);
+
+ // show the log for print
+ return formatDateTime();
+ }
+
public String formatDateTime(String pattern) {
LOG.keywordAppender()
.appendProperty("Print Pattern", formatterPattern)
@@ -57,6 +57,10 @@ public static Timestamp toSQLTimestamp(String... args) {
return getHelper().getSQLTimestamp();
}
+ public static String isoParse(String dateString) {
+ return getHelper().isoParseDateTime(dateString);
+ }
+
public static String parse(String... args) {
if(args.length == 2) {
return getHelper().parseDateTime(args[0], args[1]);
@@ -100,6 +104,9 @@ public static String lastDayOfMonth(String... args) {
return format(midnight, "midnight", args);
}
+ public static boolean isBeforeNow(String... args) {
+ return getHelper().getCurrent().isBeforeNow();
+ }
public static String now(String... args) {
return format(new DateTime(), "now", args);
@@ -62,6 +62,18 @@
<function-signature>java.sql.Time toSQLTime(java.lang.String[])</function-signature>
</function>
<function>
+ <name>isBeforeNow</name>
+ <prefix>date</prefix>
+ <function-class>org.jspringbot.keyword.date.DateUtils</function-class>
+ <function-signature>java.lang.Boolean isBeforeNow(java.lang.String[])</function-signature>
+ </function>
+ <function>
+ <name>isoParse</name>
+ <prefix>date</prefix>
+ <function-class>org.jspringbot.keyword.date.DateUtils</function-class>
+ <function-signature>java.lang.String isoParse(java.lang.String)</function-signature>
+ </function>
+ <function>
<name>toSQLTimestamp</name>
<prefix>date</prefix>
<function-class>org.jspringbot.keyword.date.DateUtils</function-class>
@@ -74,6 +74,12 @@ public void testExpression() throws Exception {
}
+ @Test
+ public void testName() throws Exception {
+ expressionHelper.evaluate("$[date:isoParse('2013-03-18T15:39:43.000+08:00')]");
+ expressionHelper.evaluationShouldBeTrue("$[date:isBeforeNow()]");
+ }
+
@Before
public void setUp() throws Throwable {
PrivateAccessor.invoke(ApplicationContextHolder.class, "set", new Class[]{ApplicationContext.class}, new Object[]{context});

0 comments on commit 1ed0bc1

Please sign in to comment.