Get date value in Pacific Standard Time for Ruby? -


we today's date in pacific standard time in ruby using date class (because use mongo , mongo can't handle time class). how can this?

essentially, want guarantee today = date.to_mongo date.today returns today's date in pst.

we're on rails 3.12 , using mongomapper.

thanks.

this little low-level (in manipulate offset, rather declare 'pst' somewhere), might trick:

d = datetime.now.new_offset('-08:00').to_date 

not sure if have daylight-saving time, make things more complicated?

you could put snippet date.today, over-ride machine settings, i'd recommend more specific like

class date   def self.today_pst     datetime.now.new_offset('-08:00').to_date   end end  today = date.to_mongo date.today_pst 

also, warning, if convert time or datetime, zone not preserved.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -