fat_period 1.0.3 → 1.1.0
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.
- checksums.yaml +4 -4
- data/fat_period.gemspec +1 -1
- data/lib/fat_period/period.rb +31 -90
- data/lib/fat_period/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51ac3735bac6324561fcbab7045abba1faf5af75617b92fabe0f9b063824c7a8
|
4
|
+
data.tar.gz: f5e8fd4a93c5fb2f4aa878bb8e18a9d19e2142ce9505845be9500d6a0bb809b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62aa2512063f7065e799b39c5ab96e110c648bfc0468e918e49f764b2d44d9d0950b52ad6c50c1780997a04f6d61295769e2732b64508e7605c5f2bcd3b49caa
|
7
|
+
data.tar.gz: ea600908598015344f193cd8679e37960be484dd60bd7d3d57e121d857a98bb27541421e3e439e1dd204c936e2799b79397f44e8c65e4361fbe2b9f509363fa3
|
data/fat_period.gemspec
CHANGED
data/lib/fat_period/period.rb
CHANGED
@@ -29,37 +29,9 @@ class Period
|
|
29
29
|
# @raise [ArgumentError] if first date is later than last date
|
30
30
|
# @return [Period]
|
31
31
|
def initialize(first, last)
|
32
|
-
|
33
|
-
|
34
|
-
elsif first.respond_to?(:to_s)
|
35
|
-
begin
|
36
|
-
@first = Date.parse(first.to_s)
|
37
|
-
rescue ArgumentError => e
|
38
|
-
if e.message =~ /invalid date/
|
39
|
-
raise ArgumentError, "invalid date '#{first}'"
|
40
|
-
end
|
41
|
-
|
42
|
-
raise
|
43
|
-
end
|
44
|
-
else
|
45
|
-
raise ArgumentError, 'use Date or String to initialize Period'
|
46
|
-
end
|
47
|
-
|
48
|
-
if last.is_a?(Date)
|
49
|
-
@last = last
|
50
|
-
elsif last.respond_to?(:to_s)
|
51
|
-
begin
|
52
|
-
@last = Date.parse(last.to_s)
|
53
|
-
rescue ArgumentError => e
|
54
|
-
if e.message =~ /invalid date/
|
55
|
-
raise ArgumentError, "you gave an invalid date '#{last}'"
|
56
|
-
end
|
32
|
+
@first = Date.ensure_date(first)
|
33
|
+
@last = Date.ensure_date(last)
|
57
34
|
|
58
|
-
raise
|
59
|
-
end
|
60
|
-
else
|
61
|
-
raise ArgumentError, 'use Date or String to initialize Period'
|
62
|
-
end
|
63
35
|
return unless @first > @last
|
64
36
|
|
65
37
|
raise ArgumentError, "Period's first date is later than its last date"
|
@@ -583,74 +555,43 @@ class Period
|
|
583
555
|
raise ArgumentError, "unknown chunk size '#{size}'"
|
584
556
|
end
|
585
557
|
|
586
|
-
if CHUNK_RANGE[size].first > length
|
587
|
-
return [self] if partial_first || partial_last
|
588
|
-
|
589
|
-
msg = "any #{size} is longer than this period's #{length} days"
|
590
|
-
raise ArgumentError, msg
|
591
|
-
end
|
592
|
-
|
593
558
|
result = []
|
594
559
|
chunk_start = first.dup
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
end
|
616
|
-
chunk_end = (chunk_start.end_of_month + 1.day).end_of_month
|
617
|
-
when :month
|
618
|
-
unless partial_first
|
619
|
-
chunk_start += 1.day until chunk_start.beginning_of_month?
|
620
|
-
end
|
621
|
-
chunk_end = chunk_start.end_of_month
|
622
|
-
when :semimonth
|
623
|
-
unless partial_first
|
624
|
-
chunk_start += 1.day until chunk_start.beginning_of_semimonth?
|
625
|
-
end
|
626
|
-
chunk_end = chunk_start.end_of_semimonth
|
627
|
-
when :biweek
|
628
|
-
unless partial_first
|
629
|
-
chunk_start += 1.day until chunk_start.beginning_of_biweek?
|
630
|
-
end
|
631
|
-
chunk_end = chunk_start.end_of_biweek
|
632
|
-
when :week
|
633
|
-
unless partial_first
|
634
|
-
chunk_start += 1.day until chunk_start.beginning_of_week?
|
635
|
-
end
|
636
|
-
chunk_end = chunk_start.end_of_week
|
637
|
-
when :day
|
638
|
-
chunk_end = chunk_start
|
639
|
-
else
|
640
|
-
raise ArgumentError, "invalid chunk size '#{size}'"
|
641
|
-
end
|
642
|
-
if chunk_end <= last
|
643
|
-
result << Period.new(chunk_start, chunk_end)
|
644
|
-
elsif round_up_last
|
560
|
+
chunk_end = chunk_start.end_of_chunk(size)
|
561
|
+
if chunk_start.beginning_of_chunk?(size) || partial_first
|
562
|
+
# Keep the first chunk if it's whole or partials allowed
|
563
|
+
result << Period.new(chunk_start, chunk_end)
|
564
|
+
chunk_start = chunk_end + 1.day
|
565
|
+
chunk_end = chunk_start.end_of_chunk(size)
|
566
|
+
else
|
567
|
+
# Discard the partial first or move to next whole chunk
|
568
|
+
chunk_start = chunk_end + 1.day
|
569
|
+
chunk_end = chunk_start.end_of_chunk(size)
|
570
|
+
end
|
571
|
+
# Add Whole chunks
|
572
|
+
while chunk_end <= last
|
573
|
+
result << Period.new(chunk_start, chunk_end)
|
574
|
+
chunk_start = chunk_end + 1.day
|
575
|
+
chunk_end = chunk_start.end_of_chunk(size)
|
576
|
+
end
|
577
|
+
# Possibly append the final chunk to result
|
578
|
+
if chunk_start < last
|
579
|
+
if round_up_last
|
645
580
|
result << Period.new(chunk_start, chunk_end)
|
646
581
|
elsif partial_last
|
647
582
|
result << Period.new(chunk_start, last)
|
648
583
|
else
|
649
|
-
|
584
|
+
result
|
650
585
|
end
|
651
|
-
|
586
|
+
elsif partial_last
|
587
|
+
# Catch the case where the period is too small to make a whole chunk and
|
588
|
+
# partial_first is false, so it did not get included as the initial
|
589
|
+
# partial chunk, yet a partial_last is allowed, so include the whole
|
590
|
+
# period as a partial chunk.
|
591
|
+
result << Period.new(first, last)
|
592
|
+
else
|
593
|
+
result
|
652
594
|
end
|
653
|
-
result
|
654
595
|
end
|
655
596
|
|
656
597
|
# @group Set operations
|
data/lib/fat_period/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fat_period
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel E. Doherty
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 4.8.1
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 4.8.1
|
111
111
|
description:
|
112
112
|
email:
|
113
113
|
- ded-law@ddoherty.net
|