swedish_holidays 1.1.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/data/2020 +48 -48
- data/data/2021 +41 -41
- data/data/2022 +45 -45
- data/data/2023 +43 -43
- data/data/2024 +29 -29
- data/data/2025 +44 -44
- data/data/2026 +42 -42
- data/data/2027 +47 -47
- data/data/2028 +49 -49
- data/data/2029 +17 -17
- data/data/2030 +43 -43
- data/data/2031 +41 -41
- data/data/2032 +45 -45
- data/data/2033 +45 -45
- data/data/2034 +43 -43
- data/data/2035 +29 -29
- data/data/2036 +46 -46
- data/data/2037 +42 -42
- data/data/2038 +49 -49
- data/data/2039 +45 -45
- data/data/2040 +35 -35
- data/data/2041 +43 -43
- data/data/2042 +41 -41
- data/data/2043 +36 -36
- data/data/2044 +51 -51
- data/lib/swedish_holidays.rb +26 -12
- data/lib/swedish_holidays/holiday.rb +23 -11
- data/lib/swedish_holidays/utils.rb +24 -4
- metadata +7 -8
data/data/2043
CHANGED
@@ -1,103 +1,103 @@
|
|
1
1
|
---
|
2
|
-
- :date: '
|
2
|
+
- :date: '2043-01-01'
|
3
3
|
:name: Nyårsdagen
|
4
4
|
:week: 1
|
5
|
-
:weekday:
|
5
|
+
:weekday: Torsdag
|
6
6
|
:yday: 1
|
7
7
|
:real_holiday: true
|
8
|
-
- :date: '
|
8
|
+
- :date: '2043-01-06'
|
9
9
|
:name: Trettondedag jul
|
10
|
-
:week:
|
11
|
-
:weekday:
|
10
|
+
:week: 2
|
11
|
+
:weekday: Tisdag
|
12
12
|
:yday: 6
|
13
13
|
:real_holiday: true
|
14
|
-
- :date: '
|
14
|
+
- :date: '2043-03-27'
|
15
15
|
:name: Långfredagen
|
16
16
|
:week: 13
|
17
17
|
:weekday: Fredag
|
18
|
-
:yday:
|
18
|
+
:yday: 86
|
19
19
|
:real_holiday: true
|
20
|
-
- :date: '
|
20
|
+
- :date: '2043-03-28'
|
21
21
|
:name: Påskafton
|
22
22
|
:week: 13
|
23
23
|
:weekday: Lördag
|
24
|
-
:yday:
|
24
|
+
:yday: 87
|
25
25
|
:real_holiday: false
|
26
|
-
- :date: '
|
26
|
+
- :date: '2043-03-29'
|
27
27
|
:name: Påskdagen
|
28
28
|
:week: 13
|
29
29
|
:weekday: Söndag
|
30
|
-
:yday:
|
30
|
+
:yday: 88
|
31
31
|
:real_holiday: true
|
32
|
-
- :date: '
|
32
|
+
- :date: '2043-03-30'
|
33
33
|
:name: Annandag påsk
|
34
34
|
:week: 14
|
35
35
|
:weekday: Måndag
|
36
|
-
:yday:
|
36
|
+
:yday: 89
|
37
37
|
:real_holiday: true
|
38
|
-
- :date: '
|
38
|
+
- :date: '2043-05-01'
|
39
39
|
:name: Första maj
|
40
40
|
:week: 18
|
41
|
-
:weekday:
|
41
|
+
:weekday: Fredag
|
42
42
|
:yday: 121
|
43
43
|
:real_holiday: true
|
44
|
-
- :date: '
|
44
|
+
- :date: '2043-05-07'
|
45
45
|
:name: Kristi himmelfärdsdag
|
46
46
|
:week: 19
|
47
47
|
:weekday: Torsdag
|
48
|
-
:yday:
|
48
|
+
:yday: 127
|
49
49
|
:real_holiday: true
|
50
|
-
- :date: '
|
50
|
+
- :date: '2043-05-17'
|
51
51
|
:name: Pingstdagen
|
52
52
|
:week: 20
|
53
53
|
:weekday: Söndag
|
54
|
-
:yday:
|
54
|
+
:yday: 137
|
55
55
|
:real_holiday: true
|
56
|
-
- :date: '
|
56
|
+
- :date: '2043-06-06'
|
57
57
|
:name: Sveriges nationaldag
|
58
58
|
:week: 23
|
59
|
-
:weekday:
|
59
|
+
:weekday: Lördag
|
60
60
|
:yday: 157
|
61
61
|
:real_holiday: true
|
62
|
-
- :date: '
|
62
|
+
- :date: '2043-06-19'
|
63
63
|
:name: Midsommarafton
|
64
64
|
:week: 25
|
65
65
|
:weekday: Fredag
|
66
|
-
:yday:
|
66
|
+
:yday: 170
|
67
67
|
:real_holiday: false
|
68
|
-
- :date: '
|
68
|
+
- :date: '2043-06-20'
|
69
69
|
:name: Midsommardagen
|
70
70
|
:week: 25
|
71
71
|
:weekday: Lördag
|
72
|
-
:yday:
|
72
|
+
:yday: 171
|
73
73
|
:real_holiday: true
|
74
|
-
- :date: '
|
74
|
+
- :date: '2043-10-31'
|
75
75
|
:name: Alla helgons dag
|
76
76
|
:week: 44
|
77
77
|
:weekday: Lördag
|
78
|
-
:yday:
|
78
|
+
:yday: 304
|
79
79
|
:real_holiday: true
|
80
|
-
- :date: '
|
80
|
+
- :date: '2043-12-24'
|
81
81
|
:name: Julafton
|
82
82
|
:week: 52
|
83
|
-
:weekday:
|
83
|
+
:weekday: Torsdag
|
84
84
|
:yday: 358
|
85
85
|
:real_holiday: false
|
86
|
-
- :date: '
|
86
|
+
- :date: '2043-12-25'
|
87
87
|
:name: Juldagen
|
88
88
|
:week: 52
|
89
|
-
:weekday:
|
89
|
+
:weekday: Fredag
|
90
90
|
:yday: 359
|
91
91
|
:real_holiday: true
|
92
|
-
- :date: '
|
92
|
+
- :date: '2043-12-26'
|
93
93
|
:name: Annandag jul
|
94
94
|
:week: 52
|
95
|
-
:weekday:
|
95
|
+
:weekday: Lördag
|
96
96
|
:yday: 360
|
97
97
|
:real_holiday: true
|
98
|
-
- :date: '
|
98
|
+
- :date: '2043-12-31'
|
99
99
|
:name: Nyårsafton
|
100
|
-
:week:
|
101
|
-
:weekday:
|
100
|
+
:week: 53
|
101
|
+
:weekday: Torsdag
|
102
102
|
:yday: 365
|
103
103
|
:real_holiday: false
|
data/data/2044
CHANGED
@@ -1,103 +1,103 @@
|
|
1
1
|
---
|
2
|
-
- :date: '
|
2
|
+
- :date: '2044-01-01'
|
3
3
|
:name: Nyårsdagen
|
4
|
-
:week:
|
5
|
-
:weekday:
|
4
|
+
:week: 53
|
5
|
+
:weekday: Fredag
|
6
6
|
:yday: 1
|
7
7
|
:real_holiday: true
|
8
|
-
- :date: '
|
8
|
+
- :date: '2044-01-06'
|
9
9
|
:name: Trettondedag jul
|
10
10
|
:week: 1
|
11
|
-
:weekday:
|
11
|
+
:weekday: Onsdag
|
12
12
|
:yday: 6
|
13
13
|
:real_holiday: true
|
14
|
-
- :date: '
|
14
|
+
- :date: '2044-04-15'
|
15
15
|
:name: Långfredagen
|
16
|
-
:week:
|
16
|
+
:week: 15
|
17
17
|
:weekday: Fredag
|
18
|
-
:yday:
|
18
|
+
:yday: 106
|
19
19
|
:real_holiday: true
|
20
|
-
- :date: '
|
20
|
+
- :date: '2044-04-16'
|
21
21
|
:name: Påskafton
|
22
|
-
:week:
|
22
|
+
:week: 15
|
23
23
|
:weekday: Lördag
|
24
|
-
:yday:
|
24
|
+
:yday: 107
|
25
25
|
:real_holiday: false
|
26
|
-
- :date: '
|
26
|
+
- :date: '2044-04-17'
|
27
27
|
:name: Påskdagen
|
28
|
-
:week:
|
28
|
+
:week: 15
|
29
29
|
:weekday: Söndag
|
30
|
-
:yday:
|
30
|
+
:yday: 108
|
31
31
|
:real_holiday: true
|
32
|
-
- :date: '
|
32
|
+
- :date: '2044-04-18'
|
33
33
|
:name: Annandag påsk
|
34
|
-
:week:
|
34
|
+
:week: 16
|
35
35
|
:weekday: Måndag
|
36
|
-
:yday:
|
36
|
+
:yday: 109
|
37
37
|
:real_holiday: true
|
38
|
-
- :date: '
|
38
|
+
- :date: '2044-05-01'
|
39
39
|
:name: Första maj
|
40
|
-
:week:
|
41
|
-
:weekday:
|
42
|
-
:yday:
|
40
|
+
:week: 17
|
41
|
+
:weekday: Söndag
|
42
|
+
:yday: 122
|
43
43
|
:real_holiday: true
|
44
|
-
- :date: '
|
44
|
+
- :date: '2044-05-26'
|
45
45
|
:name: Kristi himmelfärdsdag
|
46
|
-
:week:
|
46
|
+
:week: 21
|
47
47
|
:weekday: Torsdag
|
48
|
-
:yday:
|
48
|
+
:yday: 147
|
49
49
|
:real_holiday: true
|
50
|
-
- :date: '
|
50
|
+
- :date: '2044-06-05'
|
51
51
|
:name: Pingstdagen
|
52
|
-
:week:
|
52
|
+
:week: 22
|
53
53
|
:weekday: Söndag
|
54
|
-
:yday:
|
54
|
+
:yday: 157
|
55
55
|
:real_holiday: true
|
56
|
-
- :date: '
|
56
|
+
- :date: '2044-06-06'
|
57
57
|
:name: Sveriges nationaldag
|
58
58
|
:week: 23
|
59
|
-
:weekday:
|
60
|
-
:yday:
|
59
|
+
:weekday: Måndag
|
60
|
+
:yday: 158
|
61
61
|
:real_holiday: true
|
62
|
-
- :date: '
|
62
|
+
- :date: '2044-06-24'
|
63
63
|
:name: Midsommarafton
|
64
64
|
:week: 25
|
65
65
|
:weekday: Fredag
|
66
|
-
:yday:
|
66
|
+
:yday: 176
|
67
67
|
:real_holiday: false
|
68
|
-
- :date: '
|
68
|
+
- :date: '2044-06-25'
|
69
69
|
:name: Midsommardagen
|
70
70
|
:week: 25
|
71
71
|
:weekday: Lördag
|
72
|
-
:yday:
|
72
|
+
:yday: 177
|
73
73
|
:real_holiday: true
|
74
|
-
- :date: '
|
74
|
+
- :date: '2044-11-05'
|
75
75
|
:name: Alla helgons dag
|
76
76
|
:week: 44
|
77
77
|
:weekday: Lördag
|
78
|
-
:yday:
|
78
|
+
:yday: 310
|
79
79
|
:real_holiday: true
|
80
|
-
- :date: '
|
80
|
+
- :date: '2044-12-24'
|
81
81
|
:name: Julafton
|
82
|
-
:week:
|
83
|
-
:weekday:
|
84
|
-
:yday:
|
82
|
+
:week: 51
|
83
|
+
:weekday: Lördag
|
84
|
+
:yday: 359
|
85
85
|
:real_holiday: false
|
86
|
-
- :date: '
|
86
|
+
- :date: '2044-12-25'
|
87
87
|
:name: Juldagen
|
88
|
-
:week:
|
89
|
-
:weekday:
|
90
|
-
:yday:
|
88
|
+
:week: 51
|
89
|
+
:weekday: Söndag
|
90
|
+
:yday: 360
|
91
91
|
:real_holiday: true
|
92
|
-
- :date: '
|
92
|
+
- :date: '2044-12-26'
|
93
93
|
:name: Annandag jul
|
94
94
|
:week: 52
|
95
|
-
:weekday:
|
96
|
-
:yday:
|
95
|
+
:weekday: Måndag
|
96
|
+
:yday: 361
|
97
97
|
:real_holiday: true
|
98
|
-
- :date: '
|
98
|
+
- :date: '2044-12-31'
|
99
99
|
:name: Nyårsafton
|
100
|
-
:week:
|
101
|
-
:weekday:
|
102
|
-
:yday:
|
100
|
+
:week: 52
|
101
|
+
:weekday: Lördag
|
102
|
+
:yday: 366
|
103
103
|
:real_holiday: false
|
data/lib/swedish_holidays.rb
CHANGED
@@ -6,19 +6,33 @@ module SwedishHolidays
|
|
6
6
|
|
7
7
|
class Error < StandardError; end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
9
|
+
class << self
|
10
|
+
def [](date, real: no_arg, include_informal: no_arg)
|
11
|
+
informal = Utils.include_informal?(real, include_informal)
|
12
|
+
return Holiday.find(Utils.to_date(date), include_informal: informal) unless date.is_a? Range
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
range = Utils.to_date_range(date)
|
15
|
+
each(start: range.first, include_informal: informal).take_while { |h| range.include? h.date }
|
16
|
+
end
|
17
|
+
|
18
|
+
def holiday?(date = nil, real: no_arg, include_informal: no_arg)
|
19
|
+
informal = Utils.include_informal?(real, include_informal)
|
20
|
+
date = Utils.to_date(date)
|
21
|
+
Holiday.holiday?(date, include_informal: informal)
|
22
|
+
end
|
23
|
+
|
24
|
+
def each(start: nil, real: no_arg, include_informal: no_arg, &block)
|
25
|
+
informal = Utils.include_informal?(real, include_informal)
|
26
|
+
enumerator = Utils.enumerator(start, informal)
|
27
|
+
return enumerator.lazy unless block_given?
|
28
|
+
|
29
|
+
enumerator.each(&block)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
18
33
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
enumerator.each { |holiday| yield holiday }
|
34
|
+
def no_arg
|
35
|
+
Utils::VALUE_NOT_GIVEN
|
36
|
+
end
|
23
37
|
end
|
24
38
|
end
|
@@ -12,28 +12,36 @@ module SwedishHolidays
|
|
12
12
|
attr_reader :date, :name
|
13
13
|
|
14
14
|
class << self
|
15
|
-
def holiday?(date, real:
|
16
|
-
|
15
|
+
def holiday?(date, real: no_arg, include_informal: no_arg)
|
16
|
+
informal = Utils.include_informal?(real, include_informal)
|
17
|
+
!find(date, include_informal: informal).nil?
|
17
18
|
end
|
18
19
|
|
19
|
-
def find(date, real:
|
20
|
+
def find(date, real: no_arg, include_informal: no_arg)
|
21
|
+
informal = Utils.include_informal?(real, include_informal)
|
20
22
|
year = date.year
|
21
23
|
load(year)
|
22
24
|
holiday = loaded[year][date.yday]
|
23
|
-
return holiday
|
24
|
-
holiday&.real?
|
25
|
+
return holiday if informal
|
26
|
+
return holiday if holiday&.real?
|
25
27
|
end
|
26
28
|
|
27
|
-
def each(year = Date.today.year, real:
|
29
|
+
def each(year = Date.today.year, real: no_arg, include_informal: no_arg, &block)
|
30
|
+
informal = Utils.include_informal?(real, include_informal)
|
28
31
|
load(year)
|
29
32
|
holidays = loaded[year.to_i].values
|
30
|
-
holidays.delete_if { |holiday|
|
31
|
-
return holidays.each
|
32
|
-
|
33
|
+
holidays.delete_if { |holiday| !informal && holiday.informal? }
|
34
|
+
return holidays.each(&block) if block
|
35
|
+
|
36
|
+
holidays.each
|
33
37
|
end
|
34
38
|
|
35
39
|
private
|
36
40
|
|
41
|
+
def no_arg
|
42
|
+
Utils::VALUE_NOT_GIVEN
|
43
|
+
end
|
44
|
+
|
37
45
|
def file(year)
|
38
46
|
File.join(DATA_DIR, year.to_s)
|
39
47
|
end
|
@@ -61,7 +69,7 @@ module SwedishHolidays
|
|
61
69
|
def initialize(attr)
|
62
70
|
@date = Date.parse(attr[:date])
|
63
71
|
@name = attr[:name]
|
64
|
-
@
|
72
|
+
@informal = attr.fetch(:informal_holiday) { !attr[:real_holiday] }
|
65
73
|
end
|
66
74
|
|
67
75
|
delegate [:wday, :yday] => :date
|
@@ -75,7 +83,11 @@ module SwedishHolidays
|
|
75
83
|
end
|
76
84
|
|
77
85
|
def real?
|
78
|
-
|
86
|
+
!informal?
|
87
|
+
end
|
88
|
+
|
89
|
+
def informal?
|
90
|
+
@informal
|
79
91
|
end
|
80
92
|
end
|
81
93
|
end
|
@@ -3,11 +3,16 @@ require 'swedish_holidays/holiday'
|
|
3
3
|
|
4
4
|
module SwedishHolidays
|
5
5
|
module Utils
|
6
|
+
puts "loading Utils.."
|
7
|
+
VALUE_NOT_GIVEN = Object.new
|
8
|
+
|
6
9
|
class << self
|
7
10
|
def to_date(arg = nil)
|
8
11
|
case arg
|
9
12
|
when NilClass
|
10
13
|
Date.today
|
14
|
+
when /\d{4}\Z/
|
15
|
+
Date.parse("#{date}-01-01")
|
11
16
|
when /\d{4}-\d{2}-\d{2}/
|
12
17
|
Date.parse(arg)
|
13
18
|
when Date
|
@@ -25,17 +30,32 @@ module SwedishHolidays
|
|
25
30
|
end
|
26
31
|
end
|
27
32
|
|
28
|
-
def enumerator(start,
|
33
|
+
def enumerator(start, include_informal)
|
29
34
|
start_date = to_date(start)
|
30
|
-
Enumerator.new { |yielder| iterate(yielder, start_date,
|
35
|
+
Enumerator.new { |yielder| iterate(yielder, start_date, include_informal) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def include_informal?(real, include_informal)
|
39
|
+
warn <<~DEPRECATION if real != VALUE_NOT_GIVEN
|
40
|
+
warn 'Keyword `:real` is deprecated!
|
41
|
+
Use `:include_informal` instead (Note: that the value is inverted)'
|
42
|
+
DEPRECATION
|
43
|
+
|
44
|
+
if include_informal != VALUE_NOT_GIVEN
|
45
|
+
include_informal
|
46
|
+
elsif real != VALUE_NOT_GIVEN
|
47
|
+
!real
|
48
|
+
else
|
49
|
+
false
|
50
|
+
end
|
31
51
|
end
|
32
52
|
|
33
53
|
private
|
34
54
|
|
35
|
-
def iterate(yielder, start_date,
|
55
|
+
def iterate(yielder, start_date, include_informal)
|
36
56
|
year = start_date.year
|
37
57
|
loop do
|
38
|
-
Holiday.each(year,
|
58
|
+
Holiday.each(year, include_informal: include_informal) do |holiday|
|
39
59
|
next if holiday.date < start_date
|
40
60
|
yielder << holiday
|
41
61
|
end
|