Parse about any English textual datetime description into a time string or return false on failure

time:create(STRING $string)

# note: if you give empty string, it returns false
time:create('')
#=> FALSE

time:create("now")
#=> "2020-11-13 18:04:14.966998 UTC"

time:create("+1 week")
#=> "2020-03-11 19:57:42.713038 UTC"

# note: it is safe to give the output of time:create to time:create as many times as you like without any side effect
time:create(time:create("2020-03-11 19:57:42.713038 UTC"))
#=> "2020-03-11 19:57:42.713038 UTC"

# note: if given time is invalid, it returns FALSE
time:create("2020-03-11 19:57:42.713038 GPT")
#=> FALSE

time:create("+1 year")
#=> "2021-03-04 19:57:51.931159 UTC"

time:create("2019-09-02 12:05:33")
#=> "2019-09-02 12:05:33.000000 UTC"

time:create("1 week from now")
#=> FALSE

time:create("1 week")
#=> "2020-01-13 16:47:42.768147 UTC"

# In the following exapmle we are parsing a time string 
# with -4h offset (new york) into current timezone (UTC)
# this way you can import any time string into current default
# timezone of your application
time:create("2019-09-01T20:52:06-04:00")
#=> "2019-09-01 20:52:06.000000 -04:00"

Copyright ©2013-2022 SunSed®. All rights reserved.