cotcube-helpers 0.1.7.4 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/VERSION +1 -1
- data/lib/cotcube-helpers/datetime_ext.rb +30 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32c7ba958cf4ee90e698fbc9b09332917a8fb085234612440f4fe5d013776767
|
4
|
+
data.tar.gz: ac8f2b8aac6e5b337f2cc2a3bc1d00c5573c67c8ddfe22fadd8dfeaee4be8a18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 066b9a5f15172a43f8fb7bba7384a26d930e3ae0cb936103cdae3865331e8670eeff26f2d7a80f84feebfd393c070fb5bc37738d7faa3b1556a6cc3c7b82cbee
|
7
|
+
data.tar.gz: ea7b4c464252c118e68cf7e220a60f36d2541e32f3e478a49b921dbbc03d84de34a5d8ca0a33c29e5c7351fec019e284f9fffc3ac133795a36da1d2c7ec2af60
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.8
|
@@ -10,3 +10,33 @@ class DateTime
|
|
10
10
|
|
11
11
|
alias to_sssm to_seconds_since_sunday_morning
|
12
12
|
end
|
13
|
+
|
14
|
+
class Date
|
15
|
+
|
16
|
+
# creates a range of 2 dates, of the given calendar week, Monday to Sunday
|
17
|
+
def self.cw( week: , year: Date.today.year )
|
18
|
+
form = '%Y %W %w'
|
19
|
+
build_range = lambda {|w|
|
20
|
+
begin
|
21
|
+
( DateTime.strptime("#{year} #{w} 1", form).to_date..
|
22
|
+
DateTime.strptime("#{year} #{w} 0", form).to_date)
|
23
|
+
rescue
|
24
|
+
# beyond Dec 31st #strptime must be called with cw:0 to keep it working
|
25
|
+
( DateTime.strptime("#{year} #{w} 1", form).to_date..
|
26
|
+
DateTime.strptime("#{year+1} 0 0", form).to_date)
|
27
|
+
end
|
28
|
+
}
|
29
|
+
case week
|
30
|
+
when :current
|
31
|
+
build_range.call(Date.today.cweek)
|
32
|
+
when :last
|
33
|
+
wday = Date.today.wday
|
34
|
+
build_range.call((Date.today - (wday.zero? ? 7 : wday)).cweek)
|
35
|
+
when Integer
|
36
|
+
raise ArgumentError, "'#{week}' is not supported as calendar week, choose from (1..53)" if week <= 0 or week > 53
|
37
|
+
build_range.call(week)
|
38
|
+
else
|
39
|
+
raise ArgumentError, "'#{week}' is not a supported format for calendar week"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cotcube-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin L. Tischendorf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|