ruby - How to schedule a worker for a time in an specific Time zone in Rails? -
i have form 3 fields:
- date
- time
- time zone
users schedule task customers in country, means, in time zone. so, fill form telling:
i want task executed @ 12/08/2015, @ 15:00 in london time zone
i have these 3 params , don't mind user @ moment or from. want transform 3 fields information in utc date.
how can transform fields in unique utc date?
to explicitly specific timezone instance, use activesupport::timezone::[] , call activesupport::timezone#parse create timewithzone instance within timezone:
time = activesupport::timezone['london'].parse('12/08/2015 15:00') #=> wed, 12 aug 2015 15:00:00 bst +01:00 or using activesupport::timezone#local:
time = activesupport::timezone['london'].local(2015, 8, 12, 15, 0) #=> wed, 12 aug 2015 15:00:00 bst +01:00 calling timewithzone#utc returns time instance in utc:
time.utc # => 2015-08-12 14:00:00 utc activesupport provides time::use_zone set time.zone inside block:
time.use_zone('london') { time.zone.parse('12/08/2015 15:00') } #=> wed, 12 aug 2015 15:00:00 bst +01:00 note activerecord automatically saves datetime fields in utc, there's no need convert time utc.
Comments
Post a Comment