DanskeHelligdage 1.0.2

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.
File without changes
@@ -0,0 +1,12 @@
1
+ === 1.0.2 / 2012-03-14
2
+
3
+ * Ruby 1.9 support and support for calculating next working day [lhoeg]
4
+
5
+ === 1.0.1 / 2008-10-25
6
+
7
+ * Support for non-official public holidays (juleaftensdag, grundlovsdag and 1. maj)
8
+
9
+ === 1.0.0 / 2008-10-24
10
+
11
+ * First release
12
+
@@ -0,0 +1,14 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ danske_helligdage.gemspec
6
+ lib/danske_helligdage.rb
7
+ lib/danske_helligdage/foerste_maj.rb
8
+ lib/danske_helligdage/grundlovsdag.rb
9
+ lib/danske_helligdage/juleaftensdag.rb
10
+ lib/danske_helligdage/officielle.rb
11
+ test/test_danske_helligdage.rb
12
+ test/test_foerste_maj.rb
13
+ test/test_grundlovsdag.rb
14
+ test/test_juleaftensdag.rb
@@ -0,0 +1,71 @@
1
+ = DanskeHelligdage
2
+
3
+ * http://github.com/joerichsen/danske_helligdage/
4
+
5
+ == DESCRIPTION:
6
+
7
+ Add support for public holidays in Denmark in the Date class
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ Uses the list of public holidays in Denmark found in
12
+ https://www.borger.dk/Emner/samfundogrettigheder/kirkeogtro/Sider/officiellehelligedage.aspx
13
+
14
+ == SYNOPSIS:
15
+
16
+ Require it
17
+ require 'danske_helligdage'
18
+
19
+ Get the name of a public holiday
20
+ Date.civil(2008, 12, 25).helligdag returns 'Juledag'
21
+
22
+ Ask whether a date is a public holiday
23
+ Date.civil(2008, 12, 25).helligdag? returns true
24
+
25
+ Ask whether a date is a working day
26
+ Date.civil(2008, 12, 25).arbejdsdag? returns false
27
+
28
+ Get the number of working days for a given month
29
+ Date.arbejdsdage(2008, 1) returns 22
30
+
31
+ Or for a specific period
32
+ Date.arbejdsdage_i_periode(Date.civil(2008, 1, 1), Date.civil(2008, 12, 31)) returns 253
33
+
34
+ Note that 1. maj, grundlovsdag and juleaftensdag are not official Danish public holidays, so to enable them you do something like this
35
+ require 'danske_helligdage'
36
+ require 'danske_helligdage/juleaftensdag'
37
+
38
+ Then all of the methods above will take juleaftensdag into consideration.
39
+
40
+ == REQUIREMENTS:
41
+
42
+ * None
43
+
44
+ == INSTALL:
45
+
46
+ * sudo gem install joerichsen-danske_helligdage
47
+
48
+ == LICENSE:
49
+
50
+ (The MIT License)
51
+
52
+ Copyright (c) 2008 Jørgen Orehøj Erichsen
53
+
54
+ Permission is hereby granted, free of charge, to any person obtaining
55
+ a copy of this software and associated documentation files (the
56
+ 'Software'), to deal in the Software without restriction, including
57
+ without limitation the rights to use, copy, modify, merge, publish,
58
+ distribute, sublicense, and/or sell copies of the Software, and to
59
+ permit persons to whom the Software is furnished to do so, subject to
60
+ the following conditions:
61
+
62
+ The above copyright notice and this permission notice shall be
63
+ included in all copies or substantial portions of the Software.
64
+
65
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
66
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
67
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
68
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
69
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
70
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
71
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,13 @@
1
+ # -*- ruby coding: utf-8 -*-
2
+
3
+
4
+ require 'rubygems'
5
+ require 'hoe'
6
+ $:.unshift(File.dirname(__FILE__) + "/lib")
7
+ require 'danske_helligdage'
8
+
9
+ Hoe.new('DanskeHelligdage', DanskeHelligdage::VERSION) do |p|
10
+ p.developer('Jørgen Orehøj Erichsen', 'joe@erichsen.net')
11
+ end
12
+
13
+ # vim: syntax=Ruby
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{danske_helligdage}
3
+ s.version = "1.0.2"
4
+ s.authors = ["J\303\270rgen Oreh\303\270j Erichsen"]
5
+ s.date = %q{2012-03-14}
6
+ s.description = %q{Add support for public holidays in Denmark in the Date class}
7
+ s.email = ["joe@erichsen.net"]
8
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
9
+ s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "danske_helligdage.gemspec", "lib/danske_helligdage.rb", "lib/danske_helligdage/arbejdsdag.rb", "lib/danske_helligdage/foerste_maj.rb", "lib/danske_helligdage/grundlovsdag.rb", "lib/danske_helligdage/juleaftensdag.rb", "lib/danske_helligdage/officielle.rb"]
10
+ s.test_files = ["test/test_arbejdsdage.rb", "test/test_danske_helligdage.rb", "test/test_foerste_maj.rb", "test/test_grundlovsdag.rb", "test/test_juleaftensdag.rb"]
11
+ s.has_rdoc = true
12
+ s.homepage = %q{http://github.com/joerichsen/danske_helligdage/}
13
+ s.rdoc_options = ["--main", "README.txt"]
14
+ s.require_paths = ["lib"]
15
+ s.summary = %q{Add support for public holidays in Denmark in the Date class}
16
+ end
@@ -0,0 +1,4 @@
1
+ require 'date'
2
+ require 'danske_helligdage/officielle'
3
+
4
+ Date.send(:include, DanskeHelligdage::Officielle)
@@ -0,0 +1,20 @@
1
+ require 'danske_helligdage'
2
+
3
+ module DanskeHelligdage
4
+ module FoersteMaj
5
+
6
+ def self.included(base)
7
+ base.class_eval do
8
+ alias_method :helligdag_without_foerste_maj, :helligdag
9
+ alias_method :helligdag, :helligdag_with_foerste_maj
10
+ end
11
+ end
12
+
13
+ def helligdag_with_foerste_maj
14
+ (month == 5 && day == 1) ? '1. maj' : helligdag_without_foerste_maj
15
+ end
16
+
17
+ end
18
+ end
19
+
20
+ Date.send(:include, DanskeHelligdage::FoersteMaj)
@@ -0,0 +1,20 @@
1
+ require 'danske_helligdage'
2
+
3
+ module DanskeHelligdage
4
+ module Grundlovsdag
5
+
6
+ def self.included(base)
7
+ base.class_eval do
8
+ alias_method :helligdag_without_grundlovsdag, :helligdag
9
+ alias_method :helligdag, :helligdag_with_grundlovsdag
10
+ end
11
+ end
12
+
13
+ def helligdag_with_grundlovsdag
14
+ (month == 6 && day == 5) ? 'Grundlovsdag' : helligdag_without_grundlovsdag
15
+ end
16
+
17
+ end
18
+ end
19
+
20
+ Date.send(:include, DanskeHelligdage::Grundlovsdag)
@@ -0,0 +1,20 @@
1
+ require 'danske_helligdage'
2
+
3
+ module DanskeHelligdage
4
+ module Juleaftensdag
5
+
6
+ def self.included(base)
7
+ base.class_eval do
8
+ alias_method :helligdag_without_juleaften, :helligdag
9
+ alias_method :helligdag, :helligdag_with_juleaften
10
+ end
11
+ end
12
+
13
+ def helligdag_with_juleaften
14
+ (month == 12 && day == 24) ? 'Juleaftensdag' : helligdag_without_juleaften
15
+ end
16
+
17
+ end
18
+ end
19
+
20
+ Date.send(:include, DanskeHelligdage::Juleaftensdag)
@@ -0,0 +1,90 @@
1
+ # -*- coding: UTF-8 -*-
2
+ # An extension to the Date class that provides some methods for working with public holidays in Denmark.
3
+ module DanskeHelligdage
4
+
5
+ VERSION = '1.0.2'
6
+
7
+ module Officielle
8
+
9
+ def self.included(base)
10
+ base.extend ClassMethods
11
+ end
12
+
13
+ module ClassMethods
14
+ def arbejdsdage_i_periode(from, to)
15
+ (from..to).to_a.select { |date| date.arbejdsdag? }.length
16
+ end
17
+
18
+ def arbejdsdage(*args)
19
+ if args[0].is_a? Fixnum
20
+ year, month = args
21
+ arbejdsdage_i_periode(Date.civil(year, month), (Date.civil(year, month) >> 1) - 1)
22
+ else
23
+ arbejdsdage_i_periode(*args)
24
+ end
25
+ end
26
+ end
27
+
28
+ # Returns true if it is a working day
29
+ def arbejdsdag?
30
+ !weekend? && !helligdag?
31
+ end
32
+
33
+ # Returns true if it is a weekend
34
+ def weekend?
35
+ wday == 0 || wday == 6
36
+ end
37
+
38
+ # Returns true if it is a public holiday
39
+ def helligdag?
40
+ not helligdag.nil?
41
+ end
42
+
43
+ # Returns the name of public holiday
44
+ def helligdag
45
+ paaskedag = easter
46
+
47
+ relative_dates = {
48
+ (paaskedag - 7) => "Palmesøndag",
49
+ (paaskedag - 3) => "Skærtorsdag",
50
+ (paaskedag - 2) => "Langfredag",
51
+ (paaskedag) => "Påskedag",
52
+ (paaskedag + 1) => "2. påskedag",
53
+ (paaskedag + 26) => "Store Bededag",
54
+ (paaskedag + 39) => "Kristi himmelfartsdag",
55
+ (paaskedag + 49) => "Pinsedag",
56
+ (paaskedag + 50) => "2. pinsedag",
57
+ }
58
+
59
+ absolute_dates = {
60
+ Date.new(year, 1, 1) => "Nytårsdag",
61
+ Date.new(year, 12, 25) => "1. juledag",
62
+ Date.new(year, 12, 26) => "2. juledag",
63
+ }
64
+
65
+ (relative_dates.merge(absolute_dates))[self]
66
+ end
67
+
68
+ # Returns a date representing Easter
69
+ #
70
+ # From http://www.dayweekyear.com/faq_holidays_calculation.jsp
71
+ def easter
72
+ y = year
73
+ a = y % 19
74
+ b = y / 100
75
+ c = y % 100
76
+ d = b / 4
77
+ e = b % 4
78
+ f = (b + 8) / 25
79
+ g = (b - f + 1) / 3;
80
+ h = (19 * a + b - d - g + 15) % 30
81
+ i = c / 4
82
+ k = c % 4
83
+ l = (32 + 2 * e + 2 * i - h - k) % 7
84
+ m = (a + 11 * h + 22 * l) / 451
85
+ month = (h + l - 7 * m + 114) / 31
86
+ day = ((h + l - 7 * m + 114) % 31) + 1
87
+ Date.civil(year, month, day)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,34 @@
1
+ # -*- coding: UTF-8 -*-
2
+ require 'danske_helligdage'
3
+ require 'danske_helligdage/arbejdsdag'
4
+
5
+ class ArbejdsdageTests < Test::Unit::TestCase
6
+
7
+ def test_should_return_next_working_day
8
+ assert_equal Date.civil(2008, 5, 6), Date.civil(2008, 5, 5).arbejdsdag
9
+ end
10
+
11
+ def test_should_return_next_working_day_on_a_sunday
12
+ assert_equal Date.civil(2008, 5, 5), Date.civil(2008, 5, 4).arbejdsdag
13
+ end
14
+
15
+ def test_should_return_next_working_day_on_a_saturday
16
+ assert_equal Date.civil(2008, 5, 5), Date.civil(2008, 5, 3).arbejdsdag
17
+ end
18
+
19
+ def test_should_return_next_working_day_on_a_friday
20
+ assert_equal Date.civil(2008, 5, 5), Date.civil(2008, 5, 2).arbejdsdag
21
+ end
22
+
23
+ def test_should_return_next_working_day_on_a_holiday
24
+ assert_equal Date.civil(2008, 5, 2), Date.civil(2008, 5, 1).arbejdsdag
25
+ end
26
+
27
+ def test_should_return_next_working_day_before_a_holiday
28
+ assert_equal Date.civil(2008, 5, 2), Date.civil(2008, 4, 30).arbejdsdag
29
+ end
30
+
31
+ def test_should_return_next_3_working_day_before_holiday_and_weekend
32
+ assert_equal Date.civil(2008, 5, 6), Date.civil(2008, 4, 30).arbejdsdag(3)
33
+ end
34
+ end
@@ -0,0 +1,66 @@
1
+ # -*- coding: UTF-8 -*-
2
+ require 'danske_helligdage'
3
+
4
+ class DanskeHelligdageTests < Test::Unit::TestCase
5
+
6
+ def test_should_return_the_name_of_the_holiday
7
+ assert_equal 'Nytårsdag', Date.civil(2008, 1, 1).helligdag
8
+ assert_equal 'Skærtorsdag', Date.civil(2008, 3, 20).helligdag
9
+ assert_equal 'Langfredag', Date.civil(2008, 3, 21).helligdag
10
+ assert_equal 'Påskedag', Date.civil(2008, 3, 23).helligdag
11
+ assert_equal '2. påskedag', Date.civil(2008, 3, 24).helligdag
12
+ assert_equal 'Store Bededag', Date.civil(2008, 4, 18).helligdag
13
+ assert_equal 'Kristi himmelfartsdag', Date.civil(2008, 5, 1).helligdag
14
+ assert_equal 'Pinsedag', Date.civil(2008, 5, 11).helligdag
15
+ assert_equal '2. pinsedag', Date.civil(2008, 5, 12).helligdag
16
+ assert_equal '1. juledag', Date.civil(2008, 12, 25).helligdag
17
+ assert_equal '2. juledag', Date.civil(2008, 12, 26).helligdag
18
+ end
19
+
20
+ def test_should_return_nil_for_non_holidays
21
+ assert_nil Date.civil(2008, 1, 2).helligdag
22
+ end
23
+
24
+ def test_should_return_whether_it_is_a_holiday_or_not
25
+ assert Date.civil(2008, 1, 1).helligdag?
26
+ assert Date.civil(2008, 3, 20).helligdag?
27
+ assert Date.civil(2008, 3, 21).helligdag?
28
+ assert Date.civil(2008, 3, 23).helligdag?
29
+ assert Date.civil(2008, 3, 24).helligdag?
30
+ assert Date.civil(2008, 4, 18).helligdag?
31
+ assert Date.civil(2008, 5, 1).helligdag?
32
+ assert Date.civil(2008, 5, 11).helligdag?
33
+ assert Date.civil(2008, 5, 12).helligdag?
34
+ assert Date.civil(2008, 12, 25).helligdag?
35
+ assert Date.civil(2008, 12, 26).helligdag?
36
+ assert !Date.civil(2008, 1, 2).helligdag?
37
+ end
38
+
39
+ def test_should_return_whether_is_is_a_weekend_or_not
40
+ assert !Date.civil(2008, 10, 24).weekend?
41
+ assert Date.civil(2008, 10, 25).weekend?
42
+ assert Date.civil(2008, 10, 26).weekend?
43
+ assert !Date.civil(2008, 10, 27).weekend?
44
+ end
45
+
46
+ def test_should_return_whether_it_is_a_working_day_or_not
47
+ assert Date.civil(2008, 10, 24).arbejdsdag?
48
+ assert !Date.civil(2008, 10, 25).arbejdsdag?
49
+ assert !Date.civil(2008, 10, 26).arbejdsdag?
50
+ assert Date.civil(2008, 10, 27).arbejdsdag?
51
+ assert !Date.civil(2008, 12, 26).arbejdsdag?
52
+ assert !Date.civil(2008, 12, 27).arbejdsdag?
53
+ end
54
+
55
+ def test_should_return_the_number_of_working_days_for_a_given_month
56
+ assert_equal 22, Date.arbejdsdage(2008, 1)
57
+ assert_equal 21, Date.arbejdsdage(2008, 2)
58
+ assert_equal 18, Date.arbejdsdage(2008, 3)
59
+ end
60
+
61
+ def test_should_return_the_number_of_working_days_for_a_given_period
62
+ assert_equal 253, Date.arbejdsdage_i_periode(Date.civil(2008, 1, 1), Date.civil(2008, 12, 31))
63
+ assert_equal 253, Date.arbejdsdage(Date.civil(2008, 1, 1), Date.civil(2008, 12, 31))
64
+ end
65
+
66
+ end
@@ -0,0 +1,18 @@
1
+ require 'danske_helligdage'
2
+
3
+ class FoersteMajTests < Test::Unit::TestCase
4
+
5
+ def setup
6
+ require 'danske_helligdage/foerste_maj'
7
+ end
8
+
9
+ def teardown
10
+ # Restore the original Date class
11
+ Date.send(:include, DanskeHelligdage::Officielle)
12
+ end
13
+
14
+ def test_should_return_the_name_of_the_holiday
15
+ assert_equal '1. maj', Date.civil(2008, 5, 1).helligdag
16
+ end
17
+
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'danske_helligdage'
2
+
3
+ class GrundlovsdagTests < Test::Unit::TestCase
4
+
5
+ def setup
6
+ require 'danske_helligdage/grundlovsdag'
7
+ end
8
+
9
+ def teardown
10
+ # Restore the original Date class
11
+ Date.send(:include, DanskeHelligdage::Officielle)
12
+ end
13
+
14
+ def test_should_return_the_name_of_the_holiday
15
+ assert_equal 'Grundlovsdag', Date.civil(2008, 6, 5).helligdag
16
+ end
17
+
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'danske_helligdage'
2
+
3
+ class JuleaftensdagTests < Test::Unit::TestCase
4
+
5
+ def setup
6
+ require 'danske_helligdage/juleaftensdag'
7
+ end
8
+
9
+ def teardown
10
+ # Restore the original Date class
11
+ Date.send(:include, DanskeHelligdage::Officielle)
12
+ end
13
+
14
+ def test_should_return_the_name_of_the_holiday
15
+ assert_equal 'Juleaftensdag', Date.civil(2008, 12, 24).helligdag
16
+ end
17
+
18
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: DanskeHelligdage
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jørgen Orehøj Erichsen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: &70294084827840 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.10'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70294084827840
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ requirement: &70294084827380 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '2.16'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70294084827380
36
+ description: Add support for public holidays in Denmark in the Date class
37
+ email:
38
+ - joe@erichsen.net
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files:
42
+ - History.txt
43
+ - Manifest.txt
44
+ - README.txt
45
+ files:
46
+ - History.txt
47
+ - Manifest.txt
48
+ - README.txt
49
+ - Rakefile
50
+ - danske_helligdage.gemspec
51
+ - lib/danske_helligdage.rb
52
+ - lib/danske_helligdage/foerste_maj.rb
53
+ - lib/danske_helligdage/grundlovsdag.rb
54
+ - lib/danske_helligdage/juleaftensdag.rb
55
+ - lib/danske_helligdage/officielle.rb
56
+ - test/test_danske_helligdage.rb
57
+ - test/test_foerste_maj.rb
58
+ - test/test_grundlovsdag.rb
59
+ - test/test_juleaftensdag.rb
60
+ - test/test_arbejdsdage.rb
61
+ - .gemtest
62
+ homepage: http://github.com/joerichsen/danske_helligdage/
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --main
67
+ - README.txt
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project: danskehelligdage
84
+ rubygems_version: 1.8.10
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Add support for public holidays in Denmark in the Date class
88
+ test_files:
89
+ - test/test_arbejdsdage.rb
90
+ - test/test_danske_helligdage.rb
91
+ - test/test_foerste_maj.rb
92
+ - test/test_grundlovsdag.rb
93
+ - test/test_juleaftensdag.rb