Skip to content

Instantly share code, notes, and snippets.

@nazt
Created April 24, 2010 13:53
Show Gist options
  • Save nazt/377662 to your computer and use it in GitHub Desktop.
Save nazt/377662 to your computer and use it in GitHub Desktop.
def today= new Date() //represents the date and time when it is created
println today
def tomorrow= today + 1,
dayAfter= today + 2,
yesterday= today - 1,
dayBefore= today - 2
println "\n$dayBefore\n$yesterday\n$today\n$tomorrow\n$dayAfter\n"
assert today + 7 == today.plus(7) && today - 15 == today.minus(15)
println String.format('%tF', today)
def TEXT =/^(*TEXT)(+)(+/+/+) PAGE (+)/
// extract basename
src = 'c:/some/path/file.ext'
dst = src.replaceFirst('^.*/', '')
dst
usPhoneRegex = /^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$/
numbers = '''
(425) 555-0123
425-555-0123
425 555 0123
1-425-555-0123
'''.trim().split('\n').toList()
assert numbers.every{ it ==~ usPhoneRegex }
m = '2007-2-28' =~ /(\d{4})-(\d\d?)-(\d\d?)/
m.matches()
assert ['2007', '2', '28'] == [m[0][1], m[0][2], m[0][3]]
println m[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment