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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a685d90173074f0ee3490602a9108cec0f8a8ff6e616fce2db1ef3566d0f2ef6
4
- data.tar.gz: b08e52e6e47a233658765b4fdb3aab72d649aefff91eabb46e8cbcef6542e84e
3
+ metadata.gz: 32c7ba958cf4ee90e698fbc9b09332917a8fb085234612440f4fe5d013776767
4
+ data.tar.gz: ac8f2b8aac6e5b337f2cc2a3bc1d00c5573c67c8ddfe22fadd8dfeaee4be8a18
5
5
  SHA512:
6
- metadata.gz: b8ced4fffb8f219416f05fe6daf3e891499e788d58d1ca4ea233cfff18998972b3aa9f0be10abdda3081671e534d0346201cfa7f5442b0bc996b75a6f3b1208b
7
- data.tar.gz: 853ae393f9f3ba54321d82d2dba17e61fd6f85a4609029dee619ddcab10b2c2e5aa5dd6e7105f3f88e1e072b60034f7657a4cb53baed8188ddb67347326bce7a
6
+ metadata.gz: 066b9a5f15172a43f8fb7bba7384a26d930e3ae0cb936103cdae3865331e8670eeff26f2d7a80f84feebfd393c070fb5bc37738d7faa3b1556a6cc3c7b82cbee
7
+ data.tar.gz: ea7b4c464252c118e68cf7e220a60f36d2541e32f3e478a49b921dbbc03d84de34a5d8ca0a33c29e5c7351fec019e284f9fffc3ac133795a36da1d2c7ec2af60
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.1.8 (April 18, 2021)
2
+ - datetime_ext: Date.cw provides a range of (Date..Date) representing the according calendar week
3
+
1
4
  ## 0.1.7.4 (March 13, 2021)
2
5
  - hotfix on 0.1.7.3
3
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7.4
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.7.4
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-03-13 00:00:00.000000000 Z
11
+ date: 2021-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport