Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 5e18314139394c21b6ec82b05b750d4f42b98e6e 0 parents
@colszowka colszowka authored
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in business_time-de.gemspec
+gemspec
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2012 Christoph Olszowka, Capita Unternehmensberatung GmbH
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 README.md
@@ -0,0 +1,26 @@
+# Business Time for Germany
+
+The [business_time](https://github.com/bokmann/business_time) brings business time & days calculations to ActiveSupport.
+
+This gem pre-configures it for all german holidays, both fixed (Neujahr, Tag der Arbeit, Tag der Deutschen Einheit, Weihnachten)
+and moving (Easter & it's friends Pfingsten and Himmelfahrt). The easter date is calculated using the
+[date_easter](https://rubygems.org/gems/date_easter) gem, Pfingsten & Himmelfahrt are calculated based on that,
+so no hard-coded values here.
+
+The holidays are defined for `(2000..2099)`, which should be sufficient.
+
+## Usage
+
+ gem install business_time-de
+ # OR
+ gem 'business_time-de'
+
+ require 'business_time-de'
+ 7.business_days.after(Date.parse("2012-03-28")) # => "2012-04-10" (because of easter)
+
+For more information on the usage of the [business_time](https://github.com/bokmann/business_time) gem please
+check out it's documentation.
+
+## License
+
+Copyright (c) 2012 Christoph Olszowka, Capita Unternehmensberatung GmbH. Released under MIT License, see LICENSE for more details.
9 Rakefile
@@ -0,0 +1,9 @@
+require "bundler/gem_tasks"
+
+require 'rake/testtask'
+Rake::TestTask.new do |t|
+ t.test_files = FileList['test_suite.rb']
+ t.verbose = true
+end
+
+task :default => :test
29 business_time-de.gemspec
@@ -0,0 +1,29 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "business_time-de/version"
+
+Gem::Specification.new do |s|
+ s.name = "business_time-de"
+ s.version = BusinessTime::De::VERSION
+ s.authors = ["Christoph Olszowka"]
+ s.email = ["christoph at olszowka de"]
+ s.homepage = "https://github.com/capita/business_time-de"
+ s.summary = %q{Pre-configures business_time gem for german holidays from 2000 until 2099}
+ s.description = s.description
+
+ s.rubyforge_project = "business_time-de"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_runtime_dependency "date_easter"
+ s.add_runtime_dependency "business_time"
+ s.add_runtime_dependency "activesupport"
+
+ s.add_development_dependency "testrocket"
+ # specify any dependencies here; for example:
+ # s.add_development_dependency "rspec"
+ # s.add_runtime_dependency "rest-client"
+end
18 lib/business_time-de.rb
@@ -0,0 +1,18 @@
+require "business_time-de/version"
+require 'active_support/core_ext'
+require 'business_time'
+require 'date_easter'
+
+(2000..2099).each do |year|
+ easter_sunday = Date.easter(year)
+ BusinessTime::Config.holidays << easter_sunday # Ostersonntag
+ BusinessTime::Config.holidays << (easter_sunday - 2.days) # Karfreitag
+ BusinessTime::Config.holidays << (easter_sunday + 1.day) # Ostermontag
+ BusinessTime::Config.holidays << (easter_sunday + 39.days) # Christi Himmelfahrt
+ BusinessTime::Config.holidays << (easter_sunday + 50.days) # Pfingstmontag
+ BusinessTime::Config.holidays << Time.mktime(year, 1, 1).to_date # Neujahr
+ BusinessTime::Config.holidays << Time.mktime(year, 5, 1).to_date # Tag der Arbeit
+ BusinessTime::Config.holidays << Time.mktime(year, 10, 3).to_date # Tag der deutschen Einheit
+ BusinessTime::Config.holidays << Time.mktime(year, 12, 25).to_date # Weihnachten
+ BusinessTime::Config.holidays << Time.mktime(year, 12, 26).to_date # Weihnachten
+end
5 lib/business_time-de/version.rb
@@ -0,0 +1,5 @@
+module BusinessTime
+ module De
+ VERSION = "0.0.1"
+ end
+end
26 test_suite.rb
@@ -0,0 +1,26 @@
+require 'testrocket'
+require 'business_time-de'
+
++-> { 7.business_days.after(Date.parse("2012-03-28")).to_date == Date.parse("2012-04-10") }
++-> { Date.parse("2012-04-10").workday? }
+--> { Date.parse("2012-04-09").workday? }
+
+(2000..2099).each do |year|
+ --> { Date.parse("#{year}-01-01").workday? }
+ --> { Date.parse("#{year}-05-01").workday? }
+ --> { Date.parse("#{year}-10-03").workday? }
+ --> { Date.parse("#{year}-12-25").workday? }
+ --> { Date.parse("#{year}-12-26").workday? }
+end
+
+# Ultimate easter date list, nicked from http://www.assa.org.au/edm.html
+["2000-04-23", "2001-04-15", "2002-03-31", "2003-04-20", "2004-04-11", "2005-03-27", "2006-04-16", "2007-04-08", "2008-03-23", "2009-04-12", "2010-04-04", "2011-04-24", "2012-04-08", "2013-03-31", "2014-04-20", "2015-04-05", "2016-03-27", "2017-04-16", "2018-04-01", "2019-04-21", "2020-04-12", "2021-04-04", "2022-04-17", "2023-04-09", "2024-03-31", "2025-04-20", "2026-04-05", "2027-03-28", "2028-04-16", "2029-04-01", "2030-04-21", "2031-04-13", "2032-03-28", "2033-04-17", "2034-04-09", "2035-03-25", "2036-04-13", "2037-04-05", "2038-04-25", "2039-04-10", "2040-04-01", "2041-04-21", "2042-04-06", "2043-03-29", "2044-04-17", "2045-04-09", "2046-03-25", "2047-04-14", "2048-04-05", "2049-04-18", "2050-04-10", "2051-04-02", "2052-04-21", "2053-04-06", "2054-03-29", "2055-04-18", "2056-04-02", "2057-04-22", "2058-04-14", "2059-03-30", "2060-04-18", "2061-04-10", "2062-03-26", "2063-04-15", "2064-04-06", "2065-03-29", "2066-04-11", "2067-04-03", "2068-04-22", "2069-04-14", "2070-03-30", "2071-04-19", "2072-04-10", "2073-03-26", "2074-04-15", "2075-04-07", "2076-04-19", "2077-04-11", "2078-04-03", "2079-04-23", "2080-04-07", "2081-03-30", "2082-04-19", "2083-04-04", "2084-03-26", "2085-04-15", "2086-03-31", "2087-04-20", "2088-04-11", "2089-04-03", "2090-04-16", "2091-04-08", "2092-03-30", "2093-04-12", "2094-04-04", "2095-04-24", "2096-04-15", "2097-03-31", "2098-04-20", "2099-04-12"].each do |d|
+ easter = Date.parse(d)
+ --> { (easter + 1.day).workday? } # Ostermontag
+ --> { (easter - 1.day).workday? } # Saturday
+ --> { (easter - 2.days).workday? } # Karfreitag
+
+ +-> { (easter - 3.days).workday? } # Gründonnerstag
+ # The next business day after gründonnerstag is tuesday...
+ +-> { 1.business_day.after(easter - 3.days).to_date == (easter+2.days).to_date }
+end
Please sign in to comment.
Something went wrong with that request. Please try again.