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.
data/data/2043 CHANGED
@@ -1,103 +1,103 @@
1
1
  ---
2
- - :date: '2018-01-01'
2
+ - :date: '2043-01-01'
3
3
  :name: Nyårsdagen
4
4
  :week: 1
5
- :weekday: Måndag
5
+ :weekday: Torsdag
6
6
  :yday: 1
7
7
  :real_holiday: true
8
- - :date: '2018-01-06'
8
+ - :date: '2043-01-06'
9
9
  :name: Trettondedag jul
10
- :week: 1
11
- :weekday: Lördag
10
+ :week: 2
11
+ :weekday: Tisdag
12
12
  :yday: 6
13
13
  :real_holiday: true
14
- - :date: '2018-03-30'
14
+ - :date: '2043-03-27'
15
15
  :name: Långfredagen
16
16
  :week: 13
17
17
  :weekday: Fredag
18
- :yday: 89
18
+ :yday: 86
19
19
  :real_holiday: true
20
- - :date: '2018-03-31'
20
+ - :date: '2043-03-28'
21
21
  :name: Påskafton
22
22
  :week: 13
23
23
  :weekday: Lördag
24
- :yday: 90
24
+ :yday: 87
25
25
  :real_holiday: false
26
- - :date: '2018-04-01'
26
+ - :date: '2043-03-29'
27
27
  :name: Påskdagen
28
28
  :week: 13
29
29
  :weekday: Söndag
30
- :yday: 91
30
+ :yday: 88
31
31
  :real_holiday: true
32
- - :date: '2018-04-02'
32
+ - :date: '2043-03-30'
33
33
  :name: Annandag påsk
34
34
  :week: 14
35
35
  :weekday: Måndag
36
- :yday: 92
36
+ :yday: 89
37
37
  :real_holiday: true
38
- - :date: '2018-05-01'
38
+ - :date: '2043-05-01'
39
39
  :name: Första maj
40
40
  :week: 18
41
- :weekday: Tisdag
41
+ :weekday: Fredag
42
42
  :yday: 121
43
43
  :real_holiday: true
44
- - :date: '2018-05-10'
44
+ - :date: '2043-05-07'
45
45
  :name: Kristi himmelfärdsdag
46
46
  :week: 19
47
47
  :weekday: Torsdag
48
- :yday: 130
48
+ :yday: 127
49
49
  :real_holiday: true
50
- - :date: '2018-05-20'
50
+ - :date: '2043-05-17'
51
51
  :name: Pingstdagen
52
52
  :week: 20
53
53
  :weekday: Söndag
54
- :yday: 140
54
+ :yday: 137
55
55
  :real_holiday: true
56
- - :date: '2018-06-06'
56
+ - :date: '2043-06-06'
57
57
  :name: Sveriges nationaldag
58
58
  :week: 23
59
- :weekday: Onsdag
59
+ :weekday: Lördag
60
60
  :yday: 157
61
61
  :real_holiday: true
62
- - :date: '2018-06-22'
62
+ - :date: '2043-06-19'
63
63
  :name: Midsommarafton
64
64
  :week: 25
65
65
  :weekday: Fredag
66
- :yday: 173
66
+ :yday: 170
67
67
  :real_holiday: false
68
- - :date: '2018-06-23'
68
+ - :date: '2043-06-20'
69
69
  :name: Midsommardagen
70
70
  :week: 25
71
71
  :weekday: Lördag
72
- :yday: 174
72
+ :yday: 171
73
73
  :real_holiday: true
74
- - :date: '2018-11-03'
74
+ - :date: '2043-10-31'
75
75
  :name: Alla helgons dag
76
76
  :week: 44
77
77
  :weekday: Lördag
78
- :yday: 307
78
+ :yday: 304
79
79
  :real_holiday: true
80
- - :date: '2018-12-24'
80
+ - :date: '2043-12-24'
81
81
  :name: Julafton
82
82
  :week: 52
83
- :weekday: Måndag
83
+ :weekday: Torsdag
84
84
  :yday: 358
85
85
  :real_holiday: false
86
- - :date: '2018-12-25'
86
+ - :date: '2043-12-25'
87
87
  :name: Juldagen
88
88
  :week: 52
89
- :weekday: Tisdag
89
+ :weekday: Fredag
90
90
  :yday: 359
91
91
  :real_holiday: true
92
- - :date: '2018-12-26'
92
+ - :date: '2043-12-26'
93
93
  :name: Annandag jul
94
94
  :week: 52
95
- :weekday: Onsdag
95
+ :weekday: Lördag
96
96
  :yday: 360
97
97
  :real_holiday: true
98
- - :date: '2018-12-31'
98
+ - :date: '2043-12-31'
99
99
  :name: Nyårsafton
100
- :week: 1
101
- :weekday: Måndag
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: '2018-01-01'
2
+ - :date: '2044-01-01'
3
3
  :name: Nyårsdagen
4
- :week: 1
5
- :weekday: Måndag
4
+ :week: 53
5
+ :weekday: Fredag
6
6
  :yday: 1
7
7
  :real_holiday: true
8
- - :date: '2018-01-06'
8
+ - :date: '2044-01-06'
9
9
  :name: Trettondedag jul
10
10
  :week: 1
11
- :weekday: Lördag
11
+ :weekday: Onsdag
12
12
  :yday: 6
13
13
  :real_holiday: true
14
- - :date: '2018-03-30'
14
+ - :date: '2044-04-15'
15
15
  :name: Långfredagen
16
- :week: 13
16
+ :week: 15
17
17
  :weekday: Fredag
18
- :yday: 89
18
+ :yday: 106
19
19
  :real_holiday: true
20
- - :date: '2018-03-31'
20
+ - :date: '2044-04-16'
21
21
  :name: Påskafton
22
- :week: 13
22
+ :week: 15
23
23
  :weekday: Lördag
24
- :yday: 90
24
+ :yday: 107
25
25
  :real_holiday: false
26
- - :date: '2018-04-01'
26
+ - :date: '2044-04-17'
27
27
  :name: Påskdagen
28
- :week: 13
28
+ :week: 15
29
29
  :weekday: Söndag
30
- :yday: 91
30
+ :yday: 108
31
31
  :real_holiday: true
32
- - :date: '2018-04-02'
32
+ - :date: '2044-04-18'
33
33
  :name: Annandag påsk
34
- :week: 14
34
+ :week: 16
35
35
  :weekday: Måndag
36
- :yday: 92
36
+ :yday: 109
37
37
  :real_holiday: true
38
- - :date: '2018-05-01'
38
+ - :date: '2044-05-01'
39
39
  :name: Första maj
40
- :week: 18
41
- :weekday: Tisdag
42
- :yday: 121
40
+ :week: 17
41
+ :weekday: Söndag
42
+ :yday: 122
43
43
  :real_holiday: true
44
- - :date: '2018-05-10'
44
+ - :date: '2044-05-26'
45
45
  :name: Kristi himmelfärdsdag
46
- :week: 19
46
+ :week: 21
47
47
  :weekday: Torsdag
48
- :yday: 130
48
+ :yday: 147
49
49
  :real_holiday: true
50
- - :date: '2018-05-20'
50
+ - :date: '2044-06-05'
51
51
  :name: Pingstdagen
52
- :week: 20
52
+ :week: 22
53
53
  :weekday: Söndag
54
- :yday: 140
54
+ :yday: 157
55
55
  :real_holiday: true
56
- - :date: '2018-06-06'
56
+ - :date: '2044-06-06'
57
57
  :name: Sveriges nationaldag
58
58
  :week: 23
59
- :weekday: Onsdag
60
- :yday: 157
59
+ :weekday: Måndag
60
+ :yday: 158
61
61
  :real_holiday: true
62
- - :date: '2018-06-22'
62
+ - :date: '2044-06-24'
63
63
  :name: Midsommarafton
64
64
  :week: 25
65
65
  :weekday: Fredag
66
- :yday: 173
66
+ :yday: 176
67
67
  :real_holiday: false
68
- - :date: '2018-06-23'
68
+ - :date: '2044-06-25'
69
69
  :name: Midsommardagen
70
70
  :week: 25
71
71
  :weekday: Lördag
72
- :yday: 174
72
+ :yday: 177
73
73
  :real_holiday: true
74
- - :date: '2018-11-03'
74
+ - :date: '2044-11-05'
75
75
  :name: Alla helgons dag
76
76
  :week: 44
77
77
  :weekday: Lördag
78
- :yday: 307
78
+ :yday: 310
79
79
  :real_holiday: true
80
- - :date: '2018-12-24'
80
+ - :date: '2044-12-24'
81
81
  :name: Julafton
82
- :week: 52
83
- :weekday: Måndag
84
- :yday: 358
82
+ :week: 51
83
+ :weekday: Lördag
84
+ :yday: 359
85
85
  :real_holiday: false
86
- - :date: '2018-12-25'
86
+ - :date: '2044-12-25'
87
87
  :name: Juldagen
88
- :week: 52
89
- :weekday: Tisdag
90
- :yday: 359
88
+ :week: 51
89
+ :weekday: Söndag
90
+ :yday: 360
91
91
  :real_holiday: true
92
- - :date: '2018-12-26'
92
+ - :date: '2044-12-26'
93
93
  :name: Annandag jul
94
94
  :week: 52
95
- :weekday: Onsdag
96
- :yday: 360
95
+ :weekday: Måndag
96
+ :yday: 361
97
97
  :real_holiday: true
98
- - :date: '2018-12-31'
98
+ - :date: '2044-12-31'
99
99
  :name: Nyårsafton
100
- :week: 1
101
- :weekday: Måndag
102
- :yday: 365
100
+ :week: 52
101
+ :weekday: Lördag
102
+ :yday: 366
103
103
  :real_holiday: false
@@ -6,19 +6,33 @@ module SwedishHolidays
6
6
 
7
7
  class Error < StandardError; end
8
8
 
9
- def self.[](date, real: true)
10
- return Holiday.find(Utils.to_date(date), real: real) unless date.is_a? Range
11
- range = Utils.to_date_range(date)
12
- each(start: range.first, real: real).take_while { |h| range.include? h.date }
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
- def self.holiday?(date = nil, real: true)
16
- Holiday.holiday?(Utils.to_date(date), real: real)
17
- end
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
- def self.each(start: nil, real: true)
20
- enumerator = Utils.enumerator(start, real)
21
- return enumerator.lazy unless block_given?
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: true)
16
- !find(date, real: real).nil?
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: true)
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 unless real
24
- holiday&.real? ? holiday : nil
25
+ return holiday if informal
26
+ return holiday if holiday&.real?
25
27
  end
26
28
 
27
- def each(year = Date.today.year, real: true)
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| real && !holiday.real? }
31
- return holidays.each unless block_given?
32
- holidays.each { |holiday| yield holiday }
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
- @real = attr[:real_holiday]
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
- @real
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, real)
33
+ def enumerator(start, include_informal)
29
34
  start_date = to_date(start)
30
- Enumerator.new { |yielder| iterate(yielder, start_date, real) }
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, real)
55
+ def iterate(yielder, start_date, include_informal)
36
56
  year = start_date.year
37
57
  loop do
38
- Holiday.each(year, real: real) do |holiday|
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