fat_core 4.7.3 → 4.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66c2dafd995954b7775a200600f938570b7bc5ad0fd5e240fc8fabb1496b69ba
4
- data.tar.gz: a3b3ff6b1dfd0a81afd0ed89b24501e7ade68e9b14e40e8a3da54a59e79f39a2
3
+ metadata.gz: bd64293fd2c62f0fc9e089c000b8853e71500fcd14cc3899b45402aa33d237d4
4
+ data.tar.gz: fa7909a5eeab9e94a54c389e60257b64a626fc9d572029709509dd044ef2a410
5
5
  SHA512:
6
- metadata.gz: f5ada6fefbf2b7cd2a5adbc7f62bc207ad7b8efb55e52874ec0b6e0a8e46a7bd5bc4d5e35f135fe20ea8a6b619f28e14adecf38ea5a2b01b92dfc5aaaf9b5f31
7
- data.tar.gz: 621a7ace7268390f3dd900bc0dc7ac38c2a33381cb54bda460a4f8b0f7d8b273b907007299db2c893518c99f846325312095dd7a24b63783da800909487ade51
6
+ metadata.gz: 43a94a1cdfa9595041ec2076981bca528d4da3824baf8a459fef8c41d44c88441003acfc8b804cb52f1b3fb6dcf7e7d9aa03b2f430b8db72af7d029fdbafa558
7
+ data.tar.gz: d8c430838d4b4cb1610b9a1f7ab7cf679df6e828043b452751c0cf5bee58afab5752f5dd9184c4f04397e7e4335953414d6a7025be16ac7e3e10583992f1d3ca
data/lib/fat_core/date.rb CHANGED
@@ -802,6 +802,24 @@ module FatCore
802
802
  end
803
803
  end
804
804
 
805
+ # Return whether the date that is the beginning of the +chunk+
806
+ #
807
+ # @param chunk [Symbol] one of +:year+, +:half+, +:quarter+, +:bimonth+,
808
+ # +:month+, +:semimonth+, +:biweek+, +:week+, or +:day+.
809
+ # @return [::Boolean] whether this date begins a chunk
810
+ def beginning_of_chunk?(chunk)
811
+ self == beginning_of_chunk(chunk)
812
+ end
813
+
814
+ # Return whether the date that is the end of the +chunk+
815
+ #
816
+ # @param chunk [Symbol] one of +:year+, +:half+, +:quarter+, +:bimonth+,
817
+ # +:month+, +:semimonth+, +:biweek+, +:week+, or +:day+.
818
+ # @return [::Boolean] whether this date ends a chunk
819
+ def end_of_chunk?(chunk)
820
+ self == end_of_chunk(chunk)
821
+ end
822
+
805
823
  # @group Holidays and Workdays
806
824
 
807
825
  # Does self fall on a weekend?
@@ -1733,7 +1751,7 @@ module FatCore
1733
1751
  when Time
1734
1752
  dat.to_date
1735
1753
  else
1736
- raise ArgumentError, 'Date.ensure_date needs String, Date, or Time'
1754
+ raise ArgumentError, 'requires String, Date, DateTime, or Time'
1737
1755
  end
1738
1756
  end
1739
1757
  end
@@ -1,7 +1,7 @@
1
1
  module FatCore
2
2
  MAJOR = 4
3
- MINOR = 7
4
- PATCH = 3
3
+ MINOR = 8
4
+ PATCH = 0
5
5
 
6
6
  # FatCore version number
7
7
  VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
@@ -31,7 +31,7 @@ describe Date do
31
31
 
32
32
  it 'raises an error for unknown class' do
33
33
  expect { Date.ensure_date([2011, 11, 12]) }
34
- .to raise_error /needs String, Date, or Time/
34
+ .to raise_error /requires String, Date, DateTime, or Time/
35
35
  end
36
36
  end
37
37
 
@@ -612,6 +612,114 @@ describe Date do
612
612
  }.to raise_error(ArgumentError)
613
613
  end
614
614
 
615
+ it 'should be able to test the beginning of chunks' do
616
+ expect(Date.parse('2013-11-04').beginning_of_chunk?(:year))
617
+ .to be false
618
+ expect(Date.parse('2013-01-01').beginning_of_chunk?(:year))
619
+ .to be true
620
+ expect(Date.parse('2013-11-04').beginning_of_chunk?(:half))
621
+ .to be false
622
+ expect(Date.parse('2013-01-01').beginning_of_chunk?(:half))
623
+ .to be true
624
+ expect(Date.parse('2013-07-01').beginning_of_chunk?(:half))
625
+ .to be true
626
+ expect(Date.parse('2013-11-04').beginning_of_chunk?(:quarter))
627
+ .to be false
628
+ expect(Date.parse('2013-01-01').beginning_of_chunk?(:quarter))
629
+ .to be true
630
+ expect(Date.parse('2013-07-01').beginning_of_chunk?(:quarter))
631
+ .to be true
632
+ expect(Date.parse('2013-10-01').beginning_of_chunk?(:quarter))
633
+ .to be true
634
+ expect(Date.parse('2013-11-04').beginning_of_chunk?(:bimonth))
635
+ .to be false
636
+ expect(Date.parse('2013-01-01').beginning_of_chunk?(:bimonth))
637
+ .to be true
638
+ expect(Date.parse('2013-02-01').beginning_of_chunk?(:bimonth))
639
+ .to be false
640
+ expect(Date.parse('2013-11-04').beginning_of_chunk?(:month))
641
+ .to be false
642
+ expect(Date.parse('2013-01-01').beginning_of_chunk?(:month))
643
+ .to be true
644
+ expect(Date.parse('2013-11-04').beginning_of_chunk?(:semimonth))
645
+ .to be false
646
+ expect(Date.parse('2013-01-01').beginning_of_chunk?(:semimonth))
647
+ .to be true
648
+ expect(Date.parse('2013-01-16').beginning_of_chunk?(:semimonth))
649
+ .to be true
650
+ expect(Date.parse('2013-11-01').beginning_of_chunk?(:week))
651
+ .to be false
652
+ expect(Date.parse('2013-11-04').beginning_of_chunk?(:week))
653
+ .to be true
654
+ # Sunday is not beginning of commercial week
655
+ expect(Date.parse('2013-11-03').beginning_of_chunk?(:week))
656
+ .to be false
657
+ expect(Date.parse('2013-11-01').beginning_of_chunk?(:day))
658
+ .to be true
659
+ expect(Date.parse('2013-11-04').beginning_of_chunk?(:day))
660
+ .to be true
661
+ expect(Date.parse('2013-11-03').beginning_of_chunk?(:day))
662
+ .to be true
663
+
664
+ expect {
665
+ Date.parse('2013-11-04').beginning_of_chunk?(:wek)
666
+ }.to raise_error(ArgumentError)
667
+ end
668
+
669
+ it 'should be able to test the end of chunks' do
670
+ expect(Date.parse('2013-11-04').end_of_chunk?(:year))
671
+ .to be false
672
+ expect(Date.parse('2013-12-31').end_of_chunk?(:year))
673
+ .to be true
674
+ expect(Date.parse('2013-11-04').end_of_chunk?(:half))
675
+ .to be false
676
+ expect(Date.parse('2013-12-31').end_of_chunk?(:half))
677
+ .to be true
678
+ expect(Date.parse('2013-06-30').end_of_chunk?(:half))
679
+ .to be true
680
+ expect(Date.parse('2013-11-04').end_of_chunk?(:quarter))
681
+ .to be false
682
+ expect(Date.parse('2013-12-31').end_of_chunk?(:quarter))
683
+ .to be true
684
+ expect(Date.parse('2013-06-30').end_of_chunk?(:quarter))
685
+ .to be true
686
+ expect(Date.parse('2013-09-30').end_of_chunk?(:quarter))
687
+ .to be true
688
+ expect(Date.parse('2013-11-04').end_of_chunk?(:bimonth))
689
+ .to be false
690
+ expect(Date.parse('2013-12-31').end_of_chunk?(:bimonth))
691
+ .to be true
692
+ expect(Date.parse('2013-02-01').end_of_chunk?(:bimonth))
693
+ .to be false
694
+ expect(Date.parse('2013-11-04').end_of_chunk?(:month))
695
+ .to be false
696
+ expect(Date.parse('2013-12-31').end_of_chunk?(:month))
697
+ .to be true
698
+ expect(Date.parse('2013-11-04').end_of_chunk?(:semimonth))
699
+ .to be false
700
+ expect(Date.parse('2013-12-31').end_of_chunk?(:semimonth))
701
+ .to be true
702
+ expect(Date.parse('2013-01-15').end_of_chunk?(:semimonth))
703
+ .to be true
704
+ expect(Date.parse('2013-11-01').end_of_chunk?(:week))
705
+ .to be false
706
+ expect(Date.parse('2013-11-04').end_of_chunk?(:week))
707
+ .to be false
708
+ # Sunday is not end of commercial week
709
+ expect(Date.parse('2013-11-03').end_of_chunk?(:week))
710
+ .to be true
711
+ expect(Date.parse('2013-11-01').end_of_chunk?(:day))
712
+ .to be true
713
+ expect(Date.parse('2013-11-04').end_of_chunk?(:day))
714
+ .to be true
715
+ expect(Date.parse('2013-11-03').end_of_chunk?(:day))
716
+ .to be true
717
+
718
+ expect {
719
+ Date.parse('2013-11-04').end_of_chunk?(:wek)
720
+ }.to raise_error(ArgumentError)
721
+ end
722
+
615
723
  it 'should be able to add a chunk sym to itself' do
616
724
  # Date.today is '2012-07-18'
617
725
  expect(Date.today.add_chunk(:year)).to eq(Date.parse('2013-07-18'))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fat_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.7.3
4
+ version: 4.8.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-01-14 00:00:00.000000000 Z
11
+ date: 2020-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov