Shift operators and incremental operators can be combined to create new timestamps.
If we want to test whether the order timestamp lies between Monday 8 a.m. of this week and
Friday 8 p.m. of this week we again have to create two new timestamps. [T<w+8H]shifts the
current timestamp back to the start of the week (previous Monday at midnight) and adds
8 hours (previous Monday at 8 a.m.). [T>w<d-2d+20H]shifts the current timestamp forth to
the end of the week (next Sunday evening just before midnight), shifts to the start of the day
(start of Sunday at midnight), subtracts two days (start of Friday at midnight), and adds
20 hours (Friday 8 p.m.).
Valang supports the incremental date operators shown in Table 9-3. Any integer number
above 0 can replace the incremented value.
Table 9-3.Incremental Operators for Dates in Valang
Notation Description
+1S Adds 1 millisecond to the date.
-1S Subtracts 1 millisecond from the date.
+1s Adds 1 second to the date.
-1s Subtracts 1 second from the date.
+1m Adds 1 minute to the date.
-1m Subtracts 1 minute from the date.
+1H Adds 1 hour to the date.
-1H Subtracts 1 hour from the date.
+1d Adds 1 day to the date.
-1d Subtracts 1 day from the date.
+1w Adds 1 week to the date.
-1w Subtracts 1 week from the date.
+1M Adds 1 month to the date.
-1M Subtracts 1 month from the date.
+1y Adds 1 year to the date.
-1y Subtracts 1 year from the date.
In date expression Tcan also be replaced by a literal date value. [20050730<M]resolves to
the start of Friday, 1 July 2005 at midnight.
Valang by default supports these date formats. The formats are in the notation supported
by java.text.SimpleDateFormat.
Table 9-4.Regular Expressions for Date Formats Valang Recognizes by Default
Date Format Regular Expression
yyyyMMdd ^\d{8}$
yyyy-MM-dd ^\d{4}\-\d{2}\-\d{2}$
yyyy-MM-dd HH:mm:ss ^\d{4}\-\d{2}\-\d{2}\s+\d{2}:\d{2}:\d{2}$
yyyyMMdd HHmmss ^\d{8}\s+\d{6}$
yyyyMMdd HH:mm:ss ^\d{8}\s+\d{2}:\d{2}:\d{2}$
yyyy-MM-dd HHmmss ^\d{4}\-\d{2}\-\d{2}\s+\d{6}$
CHAPTER 9 ■VALIDATION 273