dateoperations 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +5 -0
- data/lib/dateoperations.rb +7 -11
- metadata +10 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cdb67e5aabbf75a2536a4966189c05d07700045bf491660872695a7852f69d4c
|
4
|
+
data.tar.gz: 5f5d370c07cdd8c614bbf5df3bd755f8b256dfa5a9d8fe22352f4793f171d3f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52a4e25a1d04b9cb165f507528f3886ed6564bdb04821505058b4d95c8706656901c91aaa3cd7ed7f674360c933416b9b5491ca86744e762c82bca1b8c5d8aeb
|
7
|
+
data.tar.gz: a30c075bc82530d0f99303da88c3730d2f4640c2a289c2969c93d74d13c33074ed35c7cb7585f6d9eea1d64e4b90c128ce5bfc249143450836235c31ebc95619
|
data/README.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
# DateOperations
|
2
|
+
|
3
|
+
[![](https://codescene.io/projects/5634/status.svg) Get more details at **codescene.io**.](https://codescene.io/projects/5634/jobs/latest-successful/results)
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
2
7
|
Different date operations, primarily around business days; based on the [Holidays Gem](https://github.com/holidays/holidays).
|
3
8
|
|
4
9
|
## Synopsis
|
data/lib/dateoperations.rb
CHANGED
@@ -3,10 +3,10 @@ require 'holidays'
|
|
3
3
|
|
4
4
|
##
|
5
5
|
# Different date operations, primarily around business days, based on the Holidays[https://github.com/holidays/holidays] Gem.
|
6
|
-
# - Home[
|
6
|
+
# - Home[https://github.com/msc01/dateoperations]
|
7
7
|
# - Documentation[http://dateoperations.schwarze-web.de/DateOperations.html]
|
8
8
|
class DateOperations
|
9
|
-
@country
|
9
|
+
@country = :de
|
10
10
|
|
11
11
|
class << self
|
12
12
|
# Switches to the calendar of the respective country:
|
@@ -16,30 +16,26 @@ class DateOperations
|
|
16
16
|
attr_accessor :country
|
17
17
|
end
|
18
18
|
|
19
|
-
# Returns an array with dates for the
|
19
|
+
# Returns an array with dates for the week days (Monday to Friday) between a given start and end date.
|
20
20
|
def self.week_days_between(start_date, end_date)
|
21
21
|
week_day_nbrs = (1..5)
|
22
22
|
(start_date..end_date).select { |w| week_day_nbrs.include?(w.wday) }
|
23
23
|
end
|
24
24
|
|
25
|
-
# returns the number of
|
25
|
+
# returns the number of week days (Monday to Friday) between a given start and end date.
|
26
26
|
def self.number_of_week_days_between(start_date, end_date)
|
27
27
|
week_days = week_days_between(start_date, end_date)
|
28
28
|
week_days.length
|
29
29
|
end
|
30
30
|
|
31
|
-
# Returns an array with dates
|
32
|
-
# for the "business days" = "week days" (= Monday to Friday)
|
33
|
-
# without <tt>holidays</tt>
|
31
|
+
# Returns an array with dates for the business days (week days (Monday to Friday) without holidays).
|
34
32
|
# between a given start and end date.
|
35
33
|
def self.business_days_between(start_date, end_date)
|
36
34
|
week_days = week_days_between(start_date, end_date)
|
37
35
|
week_days.reject { |b| holiday?(b) }
|
38
36
|
end
|
39
37
|
|
40
|
-
# Returns the number of
|
41
|
-
# = "week days" (= Monday to Friday)
|
42
|
-
# without <tt>holidays</tt>
|
38
|
+
# Returns the number of business days (week days (Monday to Friday) without holidays).
|
43
39
|
# between a given start and end date.
|
44
40
|
def self.number_of_business_days_between(start_date, end_date)
|
45
41
|
business_days = business_days_between(start_date, end_date)
|
@@ -51,7 +47,7 @@ class DateOperations
|
|
51
47
|
date.saturday? || date.sunday?
|
52
48
|
end
|
53
49
|
|
54
|
-
# Checks whether a given date is a holiday based on the calendar for the respective
|
50
|
+
# Checks whether a given date is a holiday based on the calendar for the respective country.
|
55
51
|
def self.holiday?(date)
|
56
52
|
return false if Holidays.on(date, DateOperations.country, :informal).empty?
|
57
53
|
true
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dateoperations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Schwarze
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: holidays
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '8'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '8'
|
27
27
|
description: Simple date operations to determine weekends, holidays, and esp. business
|
28
28
|
days. Based on the Holidays Gem.
|
29
29
|
email: michael@schwarze-web.de
|
@@ -38,7 +38,7 @@ homepage: https://github.com/msc01/dateoperations
|
|
38
38
|
licenses:
|
39
39
|
- MIT
|
40
40
|
metadata: {}
|
41
|
-
post_install_message:
|
41
|
+
post_install_message:
|
42
42
|
rdoc_options: []
|
43
43
|
require_paths:
|
44
44
|
- lib
|
@@ -53,9 +53,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
|
-
|
57
|
-
|
58
|
-
signing_key:
|
56
|
+
rubygems_version: 3.3.7
|
57
|
+
signing_key:
|
59
58
|
specification_version: 4
|
60
59
|
summary: Date Operations
|
61
60
|
test_files: []
|