danske_helligdage 1.0.1

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.
@@ -0,0 +1,8 @@
1
+ === 1.0.1 / 2008-10-25
2
+
3
+ * Support for non-official public holidays (juleaftensdag, grundlovsdag and 1. maj)
4
+
5
+ === 1.0.0 / 2008-10-24
6
+
7
+ * First release
8
+
@@ -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,12 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ $:.unshift(File.dirname(__FILE__) + "/lib")
6
+ require 'danske_helligdage'
7
+
8
+ Hoe.new('DanskeHelligdage', DanskeHelligdage::VERSION) do |p|
9
+ p.developer('Jørgen Orehøj Erichsen', 'joe@erichsen.net')
10
+ end
11
+
12
+ # vim: syntax=Ruby
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{danske_helligdage}
3
+ s.version = "1.0.1"
4
+ s.authors = ["J\303\270rgen Oreh\303\270j Erichsen"]
5
+ s.date = %q{2008-10-25}
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/foerste_maj.rb", "lib/danske_helligdage/grundlovsdag.rb", "lib/danske_helligdage/juleaftensdag.rb", "lib/danske_helligdage/officielle.rb"]
10
+ s.test_files = ["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,89 @@
1
+ # An extension to the Date class that provides some methods for working with public holidays in Denmark.
2
+ module DanskeHelligdage
3
+
4
+ VERSION = '1.0.0'
5
+
6
+ module Officielle
7
+
8
+ def self.included(base)
9
+ base.extend ClassMethods
10
+ end
11
+
12
+ module ClassMethods
13
+ def arbejdsdage_i_periode(from, to)
14
+ (from..to).to_a.select { |date| date.arbejdsdag? }.length
15
+ end
16
+
17
+ def arbejdsdage(*args)
18
+ if args[0].is_a? Fixnum
19
+ year, month = args
20
+ arbejdsdage_i_periode(Date.civil(year, month), (Date.civil(year, month) >> 1) - 1)
21
+ else
22
+ arbejdsdage_i_periode(*args)
23
+ end
24
+ end
25
+ end
26
+
27
+ # Returns true if it is a working day
28
+ def arbejdsdag?
29
+ !weekend? && !helligdag?
30
+ end
31
+
32
+ # Returns true if it is a weekend
33
+ def weekend?
34
+ wday == 0 || wday == 6
35
+ end
36
+
37
+ # Returns true if it is a public holiday
38
+ def helligdag?
39
+ not helligdag.nil?
40
+ end
41
+
42
+ # Returns the name of public holiday
43
+ def helligdag
44
+ paaskedag = easter
45
+
46
+ relative_dates = {
47
+ (paaskedag - 7) => "Palmesøndag",
48
+ (paaskedag - 3) => "Skærtorsdag",
49
+ (paaskedag - 2) => "Langfredag",
50
+ (paaskedag) => "Påskedag",
51
+ (paaskedag + 1) => "2. påskedag",
52
+ (paaskedag + 26) => "Store Bededag",
53
+ (paaskedag + 39) => "Kristi himmelfartsdag",
54
+ (paaskedag + 49) => "Pinsedag",
55
+ (paaskedag + 50) => "2. pinsedag",
56
+ }
57
+
58
+ absolute_dates = {
59
+ Date.new(year, 1, 1) => "Nytårsdag",
60
+ Date.new(year, 12, 25) => "1. juledag",
61
+ Date.new(year, 12, 26) => "2. juledag",
62
+ }
63
+
64
+ (relative_dates.merge(absolute_dates))[self]
65
+ end
66
+
67
+ # Returns a date representing Easter
68
+ #
69
+ # From http://www.dayweekyear.com/faq_holidays_calculation.jsp
70
+ def easter
71
+ y = year
72
+ a = y % 19
73
+ b = y / 100
74
+ c = y % 100
75
+ d = b / 4
76
+ e = b % 4
77
+ f = (b + 8) / 25
78
+ g = (b - f + 1) / 3;
79
+ h = (19 * a + b - d - g + 15) % 30
80
+ i = c / 4
81
+ k = c % 4
82
+ l = (32 + 2 * e + 2 * i - h - k) % 7
83
+ m = (a + 11 * h + 22 * l) / 451
84
+ month = (h + l - 7 * m + 114) / 31
85
+ day = ((h + l - 7 * m + 114) % 31) + 1
86
+ Date.civil(year, month, day)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,65 @@
1
+ require 'danske_helligdage'
2
+
3
+ class DanskeHelligdageTests < Test::Unit::TestCase
4
+
5
+ def test_should_return_the_name_of_the_holiday
6
+ assert_equal 'Nytårsdag', Date.civil(2008, 1, 1).helligdag
7
+ assert_equal 'Skærtorsdag', Date.civil(2008, 3, 20).helligdag
8
+ assert_equal 'Langfredag', Date.civil(2008, 3, 21).helligdag
9
+ assert_equal 'Påskedag', Date.civil(2008, 3, 23).helligdag
10
+ assert_equal '2. påskedag', Date.civil(2008, 3, 24).helligdag
11
+ assert_equal 'Store Bededag', Date.civil(2008, 4, 18).helligdag
12
+ assert_equal 'Kristi himmelfartsdag', Date.civil(2008, 5, 1).helligdag
13
+ assert_equal 'Pinsedag', Date.civil(2008, 5, 11).helligdag
14
+ assert_equal '2. pinsedag', Date.civil(2008, 5, 12).helligdag
15
+ assert_equal '1. juledag', Date.civil(2008, 12, 25).helligdag
16
+ assert_equal '2. juledag', Date.civil(2008, 12, 26).helligdag
17
+ end
18
+
19
+ def test_should_return_nil_for_non_holidays
20
+ assert_nil Date.civil(2008, 1, 2).helligdag
21
+ end
22
+
23
+ def test_should_return_whether_it_is_a_holiday_or_not
24
+ assert Date.civil(2008, 1, 1).helligdag?
25
+ assert Date.civil(2008, 3, 20).helligdag?
26
+ assert Date.civil(2008, 3, 21).helligdag?
27
+ assert Date.civil(2008, 3, 23).helligdag?
28
+ assert Date.civil(2008, 3, 24).helligdag?
29
+ assert Date.civil(2008, 4, 18).helligdag?
30
+ assert Date.civil(2008, 5, 1).helligdag?
31
+ assert Date.civil(2008, 5, 11).helligdag?
32
+ assert Date.civil(2008, 5, 12).helligdag?
33
+ assert Date.civil(2008, 12, 25).helligdag?
34
+ assert Date.civil(2008, 12, 26).helligdag?
35
+ assert !Date.civil(2008, 1, 2).helligdag?
36
+ end
37
+
38
+ def test_should_return_whether_is_is_a_weekend_or_not
39
+ assert !Date.civil(2008, 10, 24).weekend?
40
+ assert Date.civil(2008, 10, 25).weekend?
41
+ assert Date.civil(2008, 10, 26).weekend?
42
+ assert !Date.civil(2008, 10, 27).weekend?
43
+ end
44
+
45
+ def test_should_return_whether_it_is_a_working_day_or_not
46
+ assert Date.civil(2008, 10, 24).arbejdsdag?
47
+ assert !Date.civil(2008, 10, 25).arbejdsdag?
48
+ assert !Date.civil(2008, 10, 26).arbejdsdag?
49
+ assert Date.civil(2008, 10, 27).arbejdsdag?
50
+ assert !Date.civil(2008, 12, 26).arbejdsdag?
51
+ assert !Date.civil(2008, 12, 27).arbejdsdag?
52
+ end
53
+
54
+ def test_should_return_the_number_of_working_days_for_a_given_month
55
+ assert_equal 22, Date.arbejdsdage(2008, 1)
56
+ assert_equal 21, Date.arbejdsdage(2008, 2)
57
+ assert_equal 18, Date.arbejdsdage(2008, 3)
58
+ end
59
+
60
+ def test_should_return_the_number_of_working_days_for_a_given_period
61
+ assert_equal 253, Date.arbejdsdage_i_periode(Date.civil(2008, 1, 1), Date.civil(2008, 12, 31))
62
+ assert_equal 253, Date.arbejdsdage(Date.civil(2008, 1, 1), Date.civil(2008, 12, 31))
63
+ end
64
+
65
+ 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,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danske_helligdage
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - "J\xC3\xB8rgen Oreh\xC3\xB8j Erichsen"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-25 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Add support for public holidays in Denmark in the Date class
17
+ email:
18
+ - joe@erichsen.net
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - History.txt
25
+ - Manifest.txt
26
+ - README.txt
27
+ files:
28
+ - History.txt
29
+ - Manifest.txt
30
+ - README.txt
31
+ - Rakefile
32
+ - danske_helligdage.gemspec
33
+ - lib/danske_helligdage.rb
34
+ - lib/danske_helligdage/foerste_maj.rb
35
+ - lib/danske_helligdage/grundlovsdag.rb
36
+ - lib/danske_helligdage/juleaftensdag.rb
37
+ - lib/danske_helligdage/officielle.rb
38
+ has_rdoc: true
39
+ homepage: http://github.com/joerichsen/danske_helligdage/
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --main
45
+ - README.txt
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.5
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Add support for public holidays in Denmark in the Date class
67
+ test_files:
68
+ - test/test_danske_helligdage.rb
69
+ - test/test_foerste_maj.rb
70
+ - test/test_grundlovsdag.rb
71
+ - test/test_juleaftensdag.rb