football-timezones 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +4 -0
- data/Manifest.txt +12 -0
- data/README.md +25 -0
- data/Rakefile +32 -0
- data/config/timezones_africa.csv +4 -0
- data/config/timezones_america.csv +29 -0
- data/config/timezones_asia.csv +9 -0
- data/config/timezones_europe.csv +47 -0
- data/config/timezones_world.csv +4 -0
- data/lib/football/timezones.rb +6 -0
- data/lib/football-timezones/version.rb +24 -0
- data/lib/football-timezones.rb +167 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f628a9691af73e5ab5f28f1be1cd09bae28ecf6e064e7efc4cb91867c182bf0a
|
4
|
+
data.tar.gz: 6273d92f3482d84bf785b6c161e4b71cf84172802c3ad40ffe3119f45c7f5fdf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6424048a8a71b877fe32a3ed0278b79391f04cfea1836e09750a64aadc246f6a2df5e57560e0ff3e502b78b26a286843636b18520f346c7add1afe85bfe6e9fe
|
7
|
+
data.tar.gz: 9091b37b0f6ef280c1927b32299886318f401fbaa0c9c90da2a70d0542351ab67190e2bc9ea5f946de7557c03d279cf2983eb9cd8a75ba2e70ab0062e4c4ba68
|
data/CHANGELOG.md
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
CHANGELOG.md
|
2
|
+
Manifest.txt
|
3
|
+
README.md
|
4
|
+
Rakefile
|
5
|
+
config/timezones_africa.csv
|
6
|
+
config/timezones_america.csv
|
7
|
+
config/timezones_asia.csv
|
8
|
+
config/timezones_europe.csv
|
9
|
+
config/timezones_world.csv
|
10
|
+
lib/football-timezones.rb
|
11
|
+
lib/football-timezones/version.rb
|
12
|
+
lib/football/timezones.rb
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# football-timezones - time & timezone helpers for football (league) data
|
2
|
+
|
3
|
+
|
4
|
+
* home :: [github.com/sportdb/sport.db](https://github.com/sportdb/sport.db)
|
5
|
+
* bugs :: [github.com/sportdb/sport.db/issues](https://github.com/sportdb/sport.db/issues)
|
6
|
+
* gem :: [rubygems.org/gems/football-timezones](https://rubygems.org/gems/football-timezones)
|
7
|
+
* rdoc :: [rubydoc.info/gems/football-timezones](http://rubydoc.info/gems/football-timezones)
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
...
|
14
|
+
|
15
|
+
|
16
|
+
## License
|
17
|
+
|
18
|
+
The `football-timezones` scripts are dedicated to the public domain.
|
19
|
+
Use it as you please with no restrictions whatsoever.
|
20
|
+
|
21
|
+
|
22
|
+
## Questions? Comments?
|
23
|
+
|
24
|
+
Yes, you can. More than welcome.
|
25
|
+
See [Help & Support »](https://github.com/openfootball/help)
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'hoe'
|
2
|
+
require './lib/football-timezones/version.rb'
|
3
|
+
|
4
|
+
Hoe.spec 'football-timezones' do
|
5
|
+
|
6
|
+
self.version = SportDb::Module::Timezones::VERSION
|
7
|
+
|
8
|
+
self.summary = "football-timezones - time & timezone helpers for football (league) data"
|
9
|
+
self.description = summary
|
10
|
+
|
11
|
+
self.urls = { home: 'https://github.com/sportdb/sport.db' }
|
12
|
+
|
13
|
+
self.author = 'Gerald Bauer'
|
14
|
+
self.email = 'gerald.bauer@gmail.com'
|
15
|
+
|
16
|
+
# switch extension to .markdown for gihub formatting
|
17
|
+
self.readme_file = 'README.md'
|
18
|
+
self.history_file = 'CHANGELOG.md'
|
19
|
+
|
20
|
+
self.extra_deps = [
|
21
|
+
['tzinfo'],
|
22
|
+
['season-formats'],
|
23
|
+
['cocos'],
|
24
|
+
]
|
25
|
+
|
26
|
+
self.licenses = ['Public Domain']
|
27
|
+
|
28
|
+
self.spec_extras = {
|
29
|
+
required_ruby_version: '>= 3.1.0'
|
30
|
+
}
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
key, zone
|
2
|
+
|
3
|
+
|
4
|
+
us, America/New_York # (gmt-5) new york
|
5
|
+
ca, America/Toronto
|
6
|
+
|
7
|
+
mx, America/Mexico_City
|
8
|
+
|
9
|
+
|
10
|
+
cr, America/Costa_Rica # gmt-6
|
11
|
+
gt, America/Guatemala # gmt-6
|
12
|
+
hn, America/Tegucigalpa # gmt-6
|
13
|
+
sv, America/El_Salvador # gmt-6
|
14
|
+
ni, America/Managua # gmt-6
|
15
|
+
|
16
|
+
uy, America/Montevideo # gmt-3
|
17
|
+
pe, America/Lima # gmt-5
|
18
|
+
ec, America/Guayaquil # gmt-5
|
19
|
+
co, America/Bogota
|
20
|
+
bo, America/La_Paz # gmt-4
|
21
|
+
cl, America/Santiago # gmt-4
|
22
|
+
|
23
|
+
br, America/Sao_Paulo # gmt-3 - change to -3?
|
24
|
+
ar, America/Argentina/Buenos_Aires # gmt-3 - change to -3?
|
25
|
+
|
26
|
+
|
27
|
+
concacaf.cl, America/Mexico_City ### use mx time
|
28
|
+
copa.l, America/Sao_Paulo ### use brazil time
|
29
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
key, zone
|
2
|
+
|
3
|
+
eng, Europe/London
|
4
|
+
sco, Europe/London ## check if entry or Edingburgh or such exits
|
5
|
+
ie, Europe/Dublin
|
6
|
+
|
7
|
+
es, Europe/Madrid
|
8
|
+
de, Europe/Berlin
|
9
|
+
fr, Europe/Paris
|
10
|
+
it, Europe/Rome
|
11
|
+
|
12
|
+
pt, Europe/Lisbon
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
fi, Europe/Helsinki # +2
|
18
|
+
gr, Europe/Athens
|
19
|
+
ro, Europe/Bucharest
|
20
|
+
ua, Europe/Kyiv
|
21
|
+
|
22
|
+
|
23
|
+
ru, Europe/Moscow
|
24
|
+
tr, Europe/Istanbul # +3 turkey time/moscow time
|
25
|
+
|
26
|
+
at, Europe/Vienna
|
27
|
+
ch, Europe/Zurich
|
28
|
+
hu, Europe/Budapest
|
29
|
+
cz, Europe/Prague
|
30
|
+
sk, Europe/Bratislava # link to Prague !!!
|
31
|
+
pl, Europe/Warsaw
|
32
|
+
be, Europe/Brussels
|
33
|
+
lu, Europe/Luxembourg # link to Brussels !!!
|
34
|
+
nl, Europe/Amsterdam # link to Brussels !!!
|
35
|
+
|
36
|
+
|
37
|
+
dk, Europe/Berlin ## check if country-specific available
|
38
|
+
se, Europe/Berlin ## check if country-specific available
|
39
|
+
hr, Europe/Belgrade ## check if country-specific available
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
## for champs default for not to cet (central european time) - why? why not?
|
44
|
+
uefa.cl, Europe/Paris
|
45
|
+
uefa.el, Europe/Paris
|
46
|
+
euro, Europe/Paris
|
47
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
module SportDb
|
3
|
+
module Module
|
4
|
+
module Timezones
|
5
|
+
MAJOR = 0 ## todo: namespace inside version or something - why? why not??
|
6
|
+
MINOR = 0
|
7
|
+
PATCH = 1
|
8
|
+
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
9
|
+
|
10
|
+
def self.version
|
11
|
+
VERSION
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.banner
|
15
|
+
"football-timezones/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.root
|
19
|
+
File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
|
20
|
+
end
|
21
|
+
|
22
|
+
end # module Timezones
|
23
|
+
end # module Module
|
24
|
+
end # module SportDb
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'cocos'
|
2
|
+
require 'season/formats' ## add season support
|
3
|
+
|
4
|
+
|
5
|
+
require 'tzinfo'
|
6
|
+
|
7
|
+
|
8
|
+
## our own code
|
9
|
+
require_relative 'football-timezones/version'
|
10
|
+
|
11
|
+
|
12
|
+
####
|
13
|
+
### check - nest CET class inside UTC e.g. UTC::CET - why? why not?
|
14
|
+
## make UTC and CET into a module (not class) - why? why not?
|
15
|
+
|
16
|
+
module CET ## central european time helpers
|
17
|
+
def self.now() zone.now; end
|
18
|
+
def self.today() now.to_date; end
|
19
|
+
def self.strptime( str, format )
|
20
|
+
|
21
|
+
### fix - change to Time.strptime - why? why not?
|
22
|
+
## (simply) ignore offset; double check that hours, minutes
|
23
|
+
## get parsed as is (without applying offset)
|
24
|
+
|
25
|
+
d = DateTime.strptime( str, format )
|
26
|
+
## remove assert check - why? why not?
|
27
|
+
if d.zone != '+00:00' ### use d.offset != Ration(0,1) - why? why not?
|
28
|
+
puts "!! ASSERT - CET parse date; DateTime returns offset != +0:00"
|
29
|
+
pp d.zone
|
30
|
+
pp d
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
zone.local_time( d.year, d.month, d.day, d.hour, d.min, d.sec )
|
34
|
+
end
|
35
|
+
def self.zone() @zone ||= UTC.find_zone( 'Europe/Vienna' ); end
|
36
|
+
end # class CET
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
module UTC
|
41
|
+
def self.now() Time.now.utc; end
|
42
|
+
def self.today() now.to_date; end
|
43
|
+
|
44
|
+
## -- todo - make sure / assert it's always utc - how???
|
45
|
+
## utc = ## tz_utc.strptime( m['utcDate'], '%Y-%m-%dT%H:%M:%SZ' )
|
46
|
+
## note: DateTime.strptime is supposed to be unaware of timezones!!!
|
47
|
+
## use to parse utc
|
48
|
+
## quick hack -
|
49
|
+
## use to_time.getutc instead of utc ???
|
50
|
+
def self.strptime( str, format )
|
51
|
+
d = DateTime.strptime( str, format )
|
52
|
+
## remove assert check - why? why not?
|
53
|
+
if d.zone != '+00:00' ### use d.offset != Ration(0,1) - why? why not?
|
54
|
+
puts "!! ASSERT - UTC parse date; DateTime returns offset != +0:00"
|
55
|
+
pp d.zone
|
56
|
+
pp d
|
57
|
+
exit 1
|
58
|
+
end
|
59
|
+
## note - ignores offset if any !!!!
|
60
|
+
## todo/check - report warn if offset different from 0:00 (0/1) - why? why not?
|
61
|
+
Time.utc( d.year, d.month, d.day, d.hour, d.min, d.sec )
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.find_zone( name )
|
65
|
+
zone = TZInfo::Timezone.get( name )
|
66
|
+
## wrap tzinfo timezone in our own - for adding more (auto)checks etc.
|
67
|
+
zone ? Timezone.new( zone ) : nil
|
68
|
+
end
|
69
|
+
|
70
|
+
class Timezone ## nested inside UTC
|
71
|
+
## todo/fix
|
72
|
+
## cache timezone - why? why not?
|
73
|
+
def initialize( zone )
|
74
|
+
@zone = zone
|
75
|
+
end
|
76
|
+
|
77
|
+
def to_local( time )
|
78
|
+
## assert time is Time (not Date or DateTIme)
|
79
|
+
## and assert utc!!!
|
80
|
+
assert( time.is_a?( Time ), "time #{time} is NOT of class Time; got #{time.class.name}" )
|
81
|
+
assert( time.utc?, "time #{time} is NOT utc; utc? returns #{time.utc?}" )
|
82
|
+
local = @zone.to_local( time )
|
83
|
+
local
|
84
|
+
end
|
85
|
+
|
86
|
+
def local_time( year, month=1, mday=1, hour=0, min=0, sec=0 )
|
87
|
+
@zone.local_time( year, month, mday, hour, min, sec )
|
88
|
+
end
|
89
|
+
|
90
|
+
def now() @zone.now; end
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
def assert( cond, msg )
|
95
|
+
if cond
|
96
|
+
# do nothing
|
97
|
+
else
|
98
|
+
puts "!!! assert failed - #{msg}"
|
99
|
+
exit 1
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end # class Timezone
|
103
|
+
end # module UTC
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
module TimezoneHelper
|
109
|
+
def find_zone!( league:, season: )
|
110
|
+
@zones ||= begin
|
111
|
+
zones = {}
|
112
|
+
['timezones_america',
|
113
|
+
'timezones_asia',
|
114
|
+
'timezones_europe',
|
115
|
+
'timezones_world',].each do |name|
|
116
|
+
recs = read_csv( "#{SportDb::Module::Timezones.root}/config/#{name}.csv" )
|
117
|
+
recs.each do |rec|
|
118
|
+
zone = UTC.find_zone( rec['zone'] )
|
119
|
+
if zone.nil?
|
120
|
+
## raise ArgumentError - invalid zone
|
121
|
+
puts "!! ERROR - cannot find timezone in timezone db:"
|
122
|
+
pp rec
|
123
|
+
exit 1
|
124
|
+
end
|
125
|
+
zones[ rec['key']] = zone
|
126
|
+
end
|
127
|
+
end
|
128
|
+
zones
|
129
|
+
end
|
130
|
+
|
131
|
+
## lookup first try by league+season
|
132
|
+
league_code = league.to_s.downcase
|
133
|
+
season = Season( season )
|
134
|
+
|
135
|
+
## e.g. world+2022, etc.
|
136
|
+
key = "#{league_code}+#{season}"
|
137
|
+
zone = @zones[key]
|
138
|
+
|
139
|
+
## try league e.g. eng.1 etc.
|
140
|
+
zone = @zones[league_code] if zone.nil?
|
141
|
+
|
142
|
+
## try first code only (country code )
|
143
|
+
if zone.nil?
|
144
|
+
code, _ = league_code.split( '.', 2 )
|
145
|
+
zone = @zones[code]
|
146
|
+
end
|
147
|
+
|
148
|
+
if zone.nil? ## still not found; report error
|
149
|
+
puts "!! ERROR: no timezone found for #{league} #{season}"
|
150
|
+
exit 1
|
151
|
+
end
|
152
|
+
|
153
|
+
zone
|
154
|
+
end
|
155
|
+
end # module TimezoneHelper
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
####
|
161
|
+
### note - make find_zone! public/global by default - why? why not?
|
162
|
+
module Kernel
|
163
|
+
include TimezoneHelper
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
puts SportDb::Module::Timezones.banner ## say hello
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: football-timezones
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gerald Bauer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-09-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: tzinfo
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: season-formats
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cocos
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '7'
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '4.0'
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '7'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: hoe
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '4.1'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '4.1'
|
89
|
+
description: football-timezones - time & timezone helpers for football (league) data
|
90
|
+
email: gerald.bauer@gmail.com
|
91
|
+
executables: []
|
92
|
+
extensions: []
|
93
|
+
extra_rdoc_files:
|
94
|
+
- CHANGELOG.md
|
95
|
+
- Manifest.txt
|
96
|
+
- README.md
|
97
|
+
files:
|
98
|
+
- CHANGELOG.md
|
99
|
+
- Manifest.txt
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- config/timezones_africa.csv
|
103
|
+
- config/timezones_america.csv
|
104
|
+
- config/timezones_asia.csv
|
105
|
+
- config/timezones_europe.csv
|
106
|
+
- config/timezones_world.csv
|
107
|
+
- lib/football-timezones.rb
|
108
|
+
- lib/football-timezones/version.rb
|
109
|
+
- lib/football/timezones.rb
|
110
|
+
homepage: https://github.com/sportdb/sport.db
|
111
|
+
licenses:
|
112
|
+
- Public Domain
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options:
|
116
|
+
- "--main"
|
117
|
+
- README.md
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 3.1.0
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubygems_version: 3.4.10
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: football-timezones - time & timezone helpers for football (league) data
|
135
|
+
test_files: []
|