davispuh / TimezoneParser

Library for parsing Timezone names and abbrevations to corresponding UTC offsets and much more
The Unlicense
39 stars 1 forks source link

Need the list of windows timezones #1

Closed santoshbt closed 2 years ago

santoshbt commented 9 years ago

Hello,

This actually suites my requirement. But I want the list of timezones in windows format, withot passing any arguments. Please let me know if there is any command for the same.

davispuh commented 9 years ago

Windows timezone identifiers or windows timezone names in some language?

anyway you can get raw data with

zones      = TimezoneParser::Data::Storage.WindowsZones
timezones  = TimezoneParser::Data::Storage.WindowsTimezones
zone_names = TimezoneParser::Data::Storage.WindowsZones
offsets    = TimezoneParser::Data::Storage.WindowsOffsets
santoshbt commented 9 years ago

Hi davipush,

Thanks a ton for your reply. I think offsets gives me the proper hash, and the keys of which, serves my requirement. But however I need to pass this as an argument to a function, which in turn convert it to proper UTC time of that timezone. Something like this : tz = "West Pacific Standard Time " where "West Pacific Standard Time" is obtained by offset hash keys.

I want to perform something like this, to convert it to UTC. Time.zone = tz time = Time.zone.local( year.to_i, month.to_i, day.to_i, hour.to_i, min.to_i, sec.to_i ).getutc

Is there any command to perform this operation? since it throws error "Invalid Timezone"

davispuh commented 9 years ago

I'm not really sure what you're trying to do. Pure Ruby can't convert between different timezones using names. If you want convert between timezones you need to use library such as tzinfo.

With this TimezoneParser you can get timezone's offset by name and then create a time with such offset. Like

offset = TimezoneParser::getOffsets('West Pacific Standard Time')
time = Time.now
time_with_offset = Time.new(time.year, time.month, time.day, time.hour, time.min, time.sec, offset.first)
puts time_with_offset.getutc