libtad 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/libtad.rb +123 -0
- data/lib/services/astronomy.rb +102 -0
- data/lib/services/date_calculator.rb +155 -0
- data/lib/services/holidays.rb +34 -0
- data/lib/services/onthisday.rb +42 -0
- data/lib/services/places.rb +26 -0
- data/lib/services/time.rb +143 -0
- data/lib/types/astronomy/astronomy_current.rb +58 -0
- data/lib/types/astronomy/astronomy_day.rb +32 -0
- data/lib/types/astronomy/astronomy_day_event.rb +76 -0
- data/lib/types/astronomy/astronomy_event.rb +24 -0
- data/lib/types/astronomy/astronomy_event_class.rb +37 -0
- data/lib/types/astronomy/astronomy_location.rb +31 -0
- data/lib/types/astronomy/astronomy_object.rb +27 -0
- data/lib/types/astronomy/astronomy_object_details.rb +32 -0
- data/lib/types/astronomy/astronomy_object_type.rb +36 -0
- data/lib/types/astronomy/moonphase.rb +37 -0
- data/lib/types/date_calculator/business_days_filter.rb +39 -0
- data/lib/types/date_calculator/business_holiday.rb +26 -0
- data/lib/types/date_calculator/period.rb +44 -0
- data/lib/types/date_calculator/weekdays.rb +54 -0
- data/lib/types/holidays/holiday.rb +93 -0
- data/lib/types/holidays/holiday_state.rb +35 -0
- data/lib/types/holidays/holiday_type.rb +107 -0
- data/lib/types/onthisday/event.rb +51 -0
- data/lib/types/onthisday/event_type.rb +15 -0
- data/lib/types/onthisday/name.rb +24 -0
- data/lib/types/onthisday/person.rb +39 -0
- data/lib/types/places/country.rb +20 -0
- data/lib/types/places/geo.rb +34 -0
- data/lib/types/places/location.rb +43 -0
- data/lib/types/places/location_ref.rb +24 -0
- data/lib/types/places/place.rb +24 -0
- data/lib/types/places/region.rb +35 -0
- data/lib/types/time/datetime.rb +93 -0
- data/lib/types/time/dst_entry.rb +48 -0
- data/lib/types/time/time.rb +30 -0
- data/lib/types/time/time_change.rb +49 -0
- data/lib/types/time/timezone.rb +51 -0
- metadata +137 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
module LibTAD
|
2
|
+
module OnThisDay
|
3
|
+
# A historical event.
|
4
|
+
class Event
|
5
|
+
# @return [Integer]
|
6
|
+
# Identifier for the event.
|
7
|
+
attr_reader :id
|
8
|
+
|
9
|
+
# @return [Hash<String, String>]
|
10
|
+
# Hash of languages with corresponding event name.
|
11
|
+
attr_reader :name
|
12
|
+
|
13
|
+
# @return [::LibTAD::TADTime::TADTime]
|
14
|
+
# Date of the event.
|
15
|
+
attr_reader :date
|
16
|
+
|
17
|
+
# @return [String]
|
18
|
+
# Location of the event.
|
19
|
+
attr_reader :location
|
20
|
+
|
21
|
+
# @return [Array<String>]
|
22
|
+
# Event categories.
|
23
|
+
attr_reader :categories
|
24
|
+
|
25
|
+
# @return [Array<::LibTAD::Places::Country>]
|
26
|
+
# Related countries.
|
27
|
+
attr_reader :countries
|
28
|
+
|
29
|
+
# @return [Hash<String, String>]
|
30
|
+
# Languages with corresponding event description.
|
31
|
+
attr_reader :description
|
32
|
+
|
33
|
+
def initialize(hash)
|
34
|
+
@id = hash.fetch('id', nil)
|
35
|
+
@name = hash.fetch('name', nil)
|
36
|
+
&.map { |e| [ e['lang'], e['text'] ] }
|
37
|
+
.to_h
|
38
|
+
|
39
|
+
@date = ::LibTAD::TADTime::TADTime.new hash.fetch('date', nil)
|
40
|
+
@location = hash.fetch('location', nil)
|
41
|
+
@categories = hash.fetch('categories', nil)
|
42
|
+
@countries = hash.fetch('countries', nil)
|
43
|
+
&.map { |e| ::LibTAD::Places::Country.new(e) }
|
44
|
+
|
45
|
+
@description = hash.fetch('description', nil)
|
46
|
+
&.map { |e| [ e['lang'], e['text'] ] }
|
47
|
+
.to_h
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module LibTAD
|
2
|
+
module OnThisDay
|
3
|
+
# A full name.
|
4
|
+
class Name
|
5
|
+
# @return [String]
|
6
|
+
# First name.
|
7
|
+
attr_reader :first
|
8
|
+
|
9
|
+
# @return [String]
|
10
|
+
# Middle name.
|
11
|
+
attr_reader :middle
|
12
|
+
|
13
|
+
# @return [String]
|
14
|
+
# Last name.
|
15
|
+
attr_reader :last
|
16
|
+
|
17
|
+
def initialize(hash)
|
18
|
+
@first = hash.fetch('first', nil)
|
19
|
+
@middle = hash.fetch('middle', nil)
|
20
|
+
@last = hash.fetch('last', nil)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module LibTAD
|
2
|
+
module OnThisDay
|
3
|
+
# A historical person.
|
4
|
+
class Person
|
5
|
+
# @return [Integer]
|
6
|
+
# Identifier for the person.
|
7
|
+
attr_reader :id
|
8
|
+
|
9
|
+
# @return [::LibTAD::OnThisDay::Name]
|
10
|
+
# Full name.
|
11
|
+
attr_reader :name
|
12
|
+
|
13
|
+
# @return [::LibTAD::TADTime::TADTime]
|
14
|
+
# Date of birth.
|
15
|
+
attr_reader :birthdate
|
16
|
+
|
17
|
+
# @return [::LibTAD::TADTime::TADTime]
|
18
|
+
# Date of death, if applicable.
|
19
|
+
attr_reader :deathdate
|
20
|
+
|
21
|
+
# @return [Array<String>]
|
22
|
+
# Person categories.
|
23
|
+
attr_reader :categories
|
24
|
+
|
25
|
+
# @return [Array<String>]
|
26
|
+
# The nationalities of the person
|
27
|
+
attr_reader :nationalities
|
28
|
+
|
29
|
+
def initialize(hash)
|
30
|
+
@id = hash.fetch('id', nil)
|
31
|
+
@name = ::LibTAD::OnThisDay::Name.new hash.fetch('name', nil)
|
32
|
+
@birthdate = ::LibTAD::TADTime::TADTime.new hash['birthdate'] unless !hash.key?('birthdate')
|
33
|
+
@deathdate = ::LibTAD::TADTime::TADTime.new hash['deathdate'] unless !hash.key?('deathdate')
|
34
|
+
@categories = hash.fetch('categories', nil)
|
35
|
+
@nationalities = hash.fetch('nationalities', nil)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module LibTAD
|
2
|
+
module Places
|
3
|
+
# Information about a country.
|
4
|
+
class Country
|
5
|
+
# @return [String]
|
6
|
+
# The ISO 3166-1-alpha-2 country code.
|
7
|
+
# @see https://dev-test.timeanddate.com/docs/external-references#ISO3166 ISO3166
|
8
|
+
attr_reader :id
|
9
|
+
|
10
|
+
# @return [String]
|
11
|
+
# Full name of the country.
|
12
|
+
attr_reader :name
|
13
|
+
|
14
|
+
def initialize(hash)
|
15
|
+
@id = hash.fetch('id', nil)
|
16
|
+
@name = hash.fetch('name', nil)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module LibTAD
|
2
|
+
module Places
|
3
|
+
# Geographical information about a location.
|
4
|
+
class Geo
|
5
|
+
# @return [String]
|
6
|
+
# The name of the location.
|
7
|
+
attr_reader :name
|
8
|
+
|
9
|
+
# @return [String]
|
10
|
+
# The state of the location within the country (only if applicable).
|
11
|
+
attr_reader :state
|
12
|
+
|
13
|
+
# @return [Country]
|
14
|
+
# Country of the location.
|
15
|
+
attr_reader :country
|
16
|
+
|
17
|
+
# @return [Float]
|
18
|
+
# Geographical latitude of the location.
|
19
|
+
attr_reader :latitude
|
20
|
+
|
21
|
+
# @return [Float]
|
22
|
+
# Geographical longitude of the location.
|
23
|
+
attr_reader :longitude
|
24
|
+
|
25
|
+
def initialize(hash)
|
26
|
+
@name = hash.fetch('name', nil)
|
27
|
+
@state = hash.fetch('state', nil)
|
28
|
+
@country = Country.new hash['country'] unless !hash.key?('country')
|
29
|
+
@latitude = hash.fetch('latitude', nil)
|
30
|
+
@longitude = hash.fetch('longitude', nil)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module LibTAD
|
2
|
+
module Places
|
3
|
+
# Information about a location.
|
4
|
+
class Location
|
5
|
+
# @return [String]
|
6
|
+
# The id of the location.
|
7
|
+
attr_reader :id
|
8
|
+
|
9
|
+
# @return [String]
|
10
|
+
# The part of the queried placeid that this location matches.
|
11
|
+
attr_reader :matchparam
|
12
|
+
|
13
|
+
# @return [Geo]
|
14
|
+
# Geographical information about the location.
|
15
|
+
attr_reader :geo
|
16
|
+
|
17
|
+
# @return [::LibTAD::TADTime::TADTime]
|
18
|
+
# Time information. Only present if requested.
|
19
|
+
attr_reader :time
|
20
|
+
|
21
|
+
# @return [Array<::LibTAD::TADTime::TimeChange>]
|
22
|
+
# Time changes (daylight savings time). Only present if requested and information is available.
|
23
|
+
attr_reader :timechanges
|
24
|
+
|
25
|
+
# @return [Array<::LibTAD::Astronomy::AstronomyObject>]
|
26
|
+
# Astronomical information – sunrise and sunset times. Only for the timeservice and if requested.
|
27
|
+
attr_reader :objects
|
28
|
+
|
29
|
+
def initialize(hash)
|
30
|
+
@id = hash.fetch('id', nil)
|
31
|
+
@matchparam = hash.fetch('matchparam', nil)
|
32
|
+
@geo = Geo.new hash['geo'] unless !hash.key?('geo')
|
33
|
+
@time = ::LibTAD::TADTime::TADTime.new hash['time'] unless !hash.key?('time')
|
34
|
+
@timechanges = hash.fetch('timechanges', nil)
|
35
|
+
&.map { |e| ::LibTAD::TADTime::TimeChange.new(e) }
|
36
|
+
|
37
|
+
@objects = hash.fetch('astronomy', nil)
|
38
|
+
&.fetch('objects', nil)
|
39
|
+
&.map { |e| ::LibTAD::Astronomy::AstronomyObject.new(e) }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module LibTAD
|
2
|
+
module Places
|
3
|
+
# Information about a location referenced by a region.
|
4
|
+
class LocationRef
|
5
|
+
# @return [String]
|
6
|
+
# The ID of the location.
|
7
|
+
attr_reader :id
|
8
|
+
|
9
|
+
# @return [String]
|
10
|
+
# The name of the location.
|
11
|
+
attr_reader :name
|
12
|
+
|
13
|
+
# @return [State]
|
14
|
+
# The state of the location within the country (only if applicable).
|
15
|
+
attr_reader :state
|
16
|
+
|
17
|
+
def initialize(hash)
|
18
|
+
@id = hash.fetch('id', nil)
|
19
|
+
@name = hash.fetch('name', nil)
|
20
|
+
@state = hash.fetch('state', nil)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module LibTAD
|
2
|
+
module Places
|
3
|
+
# Information about a place.
|
4
|
+
class Place
|
5
|
+
# @return [String]
|
6
|
+
# Numerical ID of the referenced place.
|
7
|
+
attr_reader :id
|
8
|
+
|
9
|
+
# @return [String]
|
10
|
+
# Textual ID of the referenced place.
|
11
|
+
attr_reader :urlid
|
12
|
+
|
13
|
+
# @return [Geo]
|
14
|
+
# Geographical information about the location.
|
15
|
+
attr_reader :geo
|
16
|
+
|
17
|
+
def initialize(hash)
|
18
|
+
@id = hash.fetch('id', nil)
|
19
|
+
@urlid = hash.fetch('urlid', nil)
|
20
|
+
@geo = Geo.new hash['geo'] unless !hash.key?('geo')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module LibTAD
|
2
|
+
module Places
|
3
|
+
# The geographical region. Contains country, a textual description of
|
4
|
+
# the region and the name of the biggest place.
|
5
|
+
class Region
|
6
|
+
# @return [Country]
|
7
|
+
# Country which the region belongs to.
|
8
|
+
attr_reader :country
|
9
|
+
|
10
|
+
# @return [String]
|
11
|
+
# Textual description of a region.
|
12
|
+
#
|
13
|
+
# Example: All locations
|
14
|
+
# Example: most of Newfoundland and Labrador
|
15
|
+
# Example: some regions of Nunavut Territory; small region of Ontario
|
16
|
+
attr_reader :desc
|
17
|
+
|
18
|
+
# @return [String]
|
19
|
+
# Name of the biggest city within the region.
|
20
|
+
attr_reader :biggestplace
|
21
|
+
|
22
|
+
# @return [Array<LocationRef>]
|
23
|
+
# A list of all locations referenced by this region. Only returned if requested by specifying the parameter listplaces.
|
24
|
+
attr_reader :locations
|
25
|
+
|
26
|
+
def initialize(hash)
|
27
|
+
@country = Country.new hash['country'] unless !hash.key?('country')
|
28
|
+
@desc = hash.fetch('desc', nil)
|
29
|
+
@biggestplace = hash.fetch('biggestplace', nil)
|
30
|
+
@locations = hash.fetch('locations', nil)
|
31
|
+
&.map { |e| LocationRef.new(e) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module LibTAD
|
4
|
+
module TADTime
|
5
|
+
# Date and time, split up into components.
|
6
|
+
class TADDateTime
|
7
|
+
# @return [Integer]
|
8
|
+
# The year component of the timestamp.
|
9
|
+
attr_reader :year
|
10
|
+
|
11
|
+
# @return [Integer]
|
12
|
+
# The month component of the timestamp.
|
13
|
+
attr_reader :month
|
14
|
+
|
15
|
+
# @return [Integer]
|
16
|
+
# The day component of the timestamp.
|
17
|
+
attr_reader :day
|
18
|
+
|
19
|
+
# @return [Integer]
|
20
|
+
# The hour component of the timestamp.
|
21
|
+
attr_reader :hour
|
22
|
+
|
23
|
+
# @return [Integer]
|
24
|
+
# The minute component of the timestamp.
|
25
|
+
attr_reader :minute
|
26
|
+
|
27
|
+
# @return [Integer]
|
28
|
+
# The second component of the timestamp.
|
29
|
+
attr_reader :second
|
30
|
+
|
31
|
+
def initialize(year: nil, month: nil, day: nil, hour: nil, minute: nil, second: nil)
|
32
|
+
@year = year
|
33
|
+
@month = month
|
34
|
+
@day = day
|
35
|
+
@hour = hour
|
36
|
+
@minute = minute
|
37
|
+
@second = second
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Boolean]
|
41
|
+
# Compare equality to another instance.
|
42
|
+
def ==(other)
|
43
|
+
other.year == @year &&
|
44
|
+
other.month == @month &&
|
45
|
+
other.day == @day &&
|
46
|
+
other.minute == @minute &&
|
47
|
+
other.second == @second
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [::LibTAD::TADTime::TADDateTime]
|
51
|
+
# Helper function for initializing from json.
|
52
|
+
def from_json(hash)
|
53
|
+
@year = hash&.fetch('year', nil)
|
54
|
+
@month = hash&.fetch('month', nil)
|
55
|
+
@day = hash&.fetch('day', nil)
|
56
|
+
@hour = hash&.fetch('hour', nil)
|
57
|
+
@minute = hash&.fetch('minute', nil)
|
58
|
+
@second = hash&.fetch('second', nil)
|
59
|
+
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [String]
|
64
|
+
# Helper function for formatting as ISO 8601.
|
65
|
+
def to_iso8601
|
66
|
+
year = @year.to_s.rjust(4, '0')
|
67
|
+
month = @month.to_s.rjust(2, '0')
|
68
|
+
day = @day.to_s.rjust(2, '0')
|
69
|
+
"#{year}-#{month}-#{day}"
|
70
|
+
end
|
71
|
+
|
72
|
+
# @return [::LibTAD::TADTime::TADDateTime]
|
73
|
+
# Get the current time.
|
74
|
+
def now
|
75
|
+
dt = ::Time.now
|
76
|
+
@year = dt.year
|
77
|
+
@month = dt.month
|
78
|
+
@day = dt.day
|
79
|
+
@hour = dt.hour
|
80
|
+
@minute = dt.min
|
81
|
+
@second = dt.sec
|
82
|
+
|
83
|
+
self
|
84
|
+
end
|
85
|
+
|
86
|
+
# @return [::DateTime]
|
87
|
+
# Try converting to Time from the standard library.
|
88
|
+
def to_std!
|
89
|
+
::Time.new(@year, @month, @day, @hour, @minute, @second)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module LibTAD
|
2
|
+
module TADTime
|
3
|
+
# DST information about a region.
|
4
|
+
class DSTEntry
|
5
|
+
# @return [::LibTAD::Places::Region]
|
6
|
+
# The geographical region where this information is valid.
|
7
|
+
# Contains country, a textual description of the region and the name of the biggest place.
|
8
|
+
attr_reader :region
|
9
|
+
|
10
|
+
# @return [::LibTAD::TADTime::TADTimeZone]
|
11
|
+
# Information about the standard time zone. This element is always returned.
|
12
|
+
attr_reader :stdtimezone
|
13
|
+
|
14
|
+
# @return [::LibTAD::TADTime::TADTimeZone]
|
15
|
+
# Information about the daylight savings time zone. Suppressed, if there are no DST changes in the
|
16
|
+
# queried year. Please note that if the region is on daylight savings time for the whole year, this information will be returned
|
17
|
+
# the stdtimezone element. Additionally, the special element will be set to allyear.
|
18
|
+
attr_reader :dsttimezone
|
19
|
+
|
20
|
+
# @return [DstEntrySpecial]
|
21
|
+
# Indicates if the region does not observe DST at all, or is on DST all year long.
|
22
|
+
attr_reader :special
|
23
|
+
|
24
|
+
# @return [String]
|
25
|
+
# Starting date of daylight savings time. Suppressed, if there are no DST changes in the queried year.
|
26
|
+
attr_reader :dststart
|
27
|
+
|
28
|
+
# @return [String]
|
29
|
+
# Ending date of daylight savings time. Suppressed, if there are no DST changes in the queried year.
|
30
|
+
attr_reader :dstend
|
31
|
+
|
32
|
+
# @return [Array<::LibTAD::TADTime::TimeChange]
|
33
|
+
# Time changes (daylight savings time). Only present if requested and information is available.
|
34
|
+
attr_reader :timechanges
|
35
|
+
|
36
|
+
def initialize(hash)
|
37
|
+
@region = ::LibTAD::Places::Region.new hash['region'] unless !hash.key?('region')
|
38
|
+
@stdtimezone = ::LibTAD::TADTime::TADTimeZone.new hash['stdtimezone'] unless !hash.key?('stdtimezone')
|
39
|
+
@dsttimezone = ::LibTAD::TADTime::TADTimeZone.new hash['dsttimezone'] unless !hash.key?('dsttimezone')
|
40
|
+
@special = hash.dig('special', 'type')
|
41
|
+
@dststart = hash.fetch('dststart', nil)
|
42
|
+
@dstend = hash.fetch('dstend', nil)
|
43
|
+
@timechanges = hash.fetch('timechanges', nil)
|
44
|
+
&.map { |e| ::LibTAD::TADTime::TimeChange.new(e) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|