Module: LibTAD::Client::TimeService
- Included in:
- LibTAD::Client
- Defined in:
- lib/services/time.rb
Overview
Time API.
Instance Method Summary collapse
-
#convert_time(from_id:, to_id: nil, iso: nil, datetime: nil, lang: nil, radius: nil, time_changes: nil, timezone: nil) ⇒ ::LibTAD::TADTime::TADTime, Array<::LibTAD::Places::Locations>
The Converttime service can be used to convert any time from UTC or any of the supported locations to any other of the supported locations.
-
#get_current_time(place_id: nil, query: nil, qlimit: nil, geo: nil, lang: nil, radius: nil, sun: nil, time: nil, time_changes: nil, timezone: nil) ⇒ Array<::LibTAD::Places::Location>
The Time service can be used to retrieve the current time in one or more places.
-
#get_daylight_savings_time(year: nil, country: nil, lang: nil, list_places: nil, only_dst: nil, time_changes: nil) ⇒ Array<::LibTAD::DST::DSTEntry>
The Dstlist service can be used to obtain data about time zones for all supported countries in our database.
Instance Method Details
#convert_time(from_id:, to_id: nil, iso: nil, datetime: nil, lang: nil, radius: nil, time_changes: nil, timezone: nil) ⇒ ::LibTAD::TADTime::TADTime, Array<::LibTAD::Places::Locations>
The Converttime service can be used to convert any time from UTC or any of the supported locations to any other of the supported locations. You have to specify a time stamp either in ISO8601 representation via the iso argument, or you have to specify the date via the datetime argument. Skipped components will not yield an error message, but use a default value instead (which corresponds to 01.01.2001, 00:00:00).
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/services/time.rb', line 67 def convert_time( from_id:, to_id: nil, iso: nil, datetime: nil, lang: nil, radius: nil, time_changes: nil, timezone: nil ) args = { fromid: from_id, toid: to_id, iso: iso, year: (datetime.year unless datetime.nil?), month: (datetime.month unless datetime.nil?), day: (datetime.day unless datetime.nil?), hour: (datetime.hour unless datetime.nil?), min: (datetime.minute unless datetime.nil?), sec: (datetime.second unless datetime.nil?), lang: lang, radius: radius, timechanges: time_changes, tz: timezone }.compact response = get('converttime', args) utc = ::LibTAD::TADTime::TADTime.new response.dig('utc', 'time') unless response.dig('utc', 'time').nil? locations = response.fetch('locations', []) .map { |e| ::LibTAD::Places::Location.new(e) } return utc, locations end |
#get_current_time(place_id: nil, query: nil, qlimit: nil, geo: nil, lang: nil, radius: nil, sun: nil, time: nil, time_changes: nil, timezone: nil) ⇒ Array<::LibTAD::Places::Location>
The Time service can be used to retrieve the current time in one or more places. Additionally, information about time zones and related changes and the time of sunrise and sunset can be queried.
Either a place_id or a query is required.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/services/time.rb', line 21 def get_current_time( place_id: nil, query: nil, qlimit: nil, geo: nil, lang: nil, radius: nil, sun: nil, time: nil, time_changes: nil, timezone: nil ) args = { placeid: place_id, query: query, qlimit: qlimit, geo: geo, lang: lang, radius: radius, sun: sun, time: time, timechanges: time_changes, tz: timezone }.compact response = get('timeservice', args) locations = response.fetch('locations', []) locations.collect do |e| ::LibTAD::Places::Location.new(e) end end |
#get_daylight_savings_time(year: nil, country: nil, lang: nil, list_places: nil, only_dst: nil, time_changes: nil) ⇒ Array<::LibTAD::DST::DSTEntry>
The Dstlist service can be used to obtain data about time zones for all supported countries in our database. This includes the start and end date of daylight savings time, and UTC offset for the time zones.
The resulting data is aggregated on country and time zone level. By default, only information from countries which actually observe DST is returned without listing the individually affected locations – see the parameters list_places and only_dst to change this behavior.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/services/time.rb', line 115 def get_daylight_savings_time( year: nil, country: nil, lang: nil, list_places: nil, only_dst: nil, time_changes: nil ) args = { year: year, country: country, lang: lang, listplaces: list_places, onlydst: only_dst, timechanges: time_changes }.compact response = get('dstlist', args) dstlist = response.fetch('dstlist', []) dstlist.collect do |e| ::LibTAD::TADTime::DSTEntry.new(e) end end |