fat_core 5.3.0 → 5.4.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: c2376c4bac5a7a1702ae4361cca280a07b1bfde4304f42fad41e0f37754d41c8
4
- data.tar.gz: e87c81524e1901bf80443b421d62ad8ebffe7212916f0bd18817625e79795985
3
+ metadata.gz: 6915be154abea741bce220665d425858a13c22aacdcff27952fda89627d0349c
4
+ data.tar.gz: 82fbae6f418d862154ba909c1f6097d2b82f020eddb740fa207285ee9bb8db3a
5
5
  SHA512:
6
- metadata.gz: c0b95bc966b857fae1bcfbf2b38dcb8e4275dee5b269091944f2dcd08830162ebf22b98072a49b9b40e1599b7c0f940beeffa4e08f9f6b9f05dc003ba81a3e8c
7
- data.tar.gz: 6cf190c0656ba641ccfe10a27e832d9bbe2bb71dde2491c97179ae4acc677af884679a4c635aefe40379e5a022dda71549c705cc6c05e71a5e4d7037639c193b
6
+ metadata.gz: 71698e9642833bd200638b30b879b86eaf21f44ee690048299597982ee0abfb4ddbd2302f3b87d649dcd4963f35de8e04f79cda705fda72cb0bcfb8efb3ae158
7
+ data.tar.gz: 03407fbd6b3340c9742df04dff407ddd695ebd2ecb7f47ff7304e095be8b27aac933a48573d35279e20b6f3df922908f2d4d3f9043fcac29296dbc3d9ca84228
data/lib/fat_core/date.rb CHANGED
@@ -57,6 +57,9 @@ module FatCore
57
57
  # to find in commercial situations.
58
58
  EOT = ::Date.parse('3000-12-31')
59
59
 
60
+ # Symbols for each of the days of the week, e.g., :sunday, :monday, etc.
61
+ DAYSYMS = ::Date::DAYNAMES.map(&:downcase).map(&:to_sym)
62
+
60
63
  # :category: Formatting
61
64
  # @group Formatting
62
65
 
@@ -515,12 +518,56 @@ module FatCore
515
518
 
516
519
  # :category: Relative ::Dates
517
520
 
521
+ # In order to accomodate biweeks, we adopt the convention that weeks are
522
+ # numbered so that whatever week contains the year's first
523
+ # Date.beginning_of_week (usually Sunday or Monday) is week number 1.
524
+ # Biweeks are then pairs of weeks: an odd numbered week first, followed by
525
+ # an even numbered week last.
526
+ def week_number
527
+ start_of_weeks = ::Date.new(year, 1, 1)
528
+ bow_wday = DAYSYMS.index(::Date.beginning_of_week)
529
+ start_of_weeks += 1 until start_of_weeks.wday == bow_wday
530
+ if yday >= start_of_weeks.yday
531
+ ((yday - start_of_weeks.yday) / 7) + 1
532
+ else
533
+ # One of the days before the start of the year's first week, so it
534
+ # belongs to the last week of the prior year.
535
+ Date.new(year - 1, 12, 31).week_number
536
+ end
537
+ end
538
+
539
+ # Return the date that is the first day of the biweek in which self
540
+ # falls, or the first day of the year, whichever is later.
541
+ # @return [::Date]
542
+ def beginning_of_biweek
543
+ if week_number.odd?
544
+ beginning_of_week
545
+ else
546
+ (self - 1.week).beginning_of_week
547
+ end
548
+ end
549
+
550
+ # :category: Relative ::Dates
551
+
552
+ # Return the date that is the last day of the biweek in which
553
+ # self falls, or the last day of the year, whichever if earlier.
554
+ # @return [::Date]
555
+ def end_of_biweek
556
+ if week_number.even?
557
+ end_of_week
558
+ else
559
+ (self + 1.week).end_of_week
560
+ end
561
+ end
562
+
563
+ # NOTE: Date#end_of_week and Date#beginning_of_week is defined in ActiveSupport
564
+
518
565
  # Return the date that is the first day of the commercial biweek in which
519
566
  # self falls. A biweek is a period of two commercial weeks starting with an
520
567
  # odd-numbered week and with each week starting in Monday and ending on
521
568
  # Sunday.
522
569
  # @return [::Date]
523
- def beginning_of_biweek
570
+ def beginning_of_bicweek
524
571
  if cweek.odd?
525
572
  beginning_of_week(::Date.beginning_of_week)
526
573
  else
@@ -537,7 +584,7 @@ module FatCore
537
584
  # In the last week of the year (if it is not part of next year's first
538
585
  # week) the end of the biweek will not extend beyond self's week, so that
539
586
  # week 1 of the following year will start a new biweek. @return [::Date]
540
- def end_of_biweek
587
+ def end_of_bicweek
541
588
  if cweek >= 52 && end_of_week(::Date.beginning_of_week).year > year
542
589
  end_of_week(::Date.beginning_of_week)
543
590
  elsif cweek.odd?
@@ -2,7 +2,7 @@
2
2
 
3
3
  module FatCore
4
4
  MAJOR = 5
5
- MINOR = 3
5
+ MINOR = 4
6
6
  PATCH = 0
7
7
 
8
8
  # FatCore version number
@@ -379,7 +379,7 @@ describe Date do
379
379
  expect(described_class.parse_spec('10', :to)).to eq described_class.parse('2012-10-31')
380
380
  expect { described_class.parse_spec('99') }.to raise_error(ArgumentError)
381
381
  # This is a valid day-of-year spec
382
- expect { described_class.parse_spec('011') }.not_to raise_error(ArgumentError)
382
+ expect { described_class.parse_spec('011') }.not_to raise_error
383
383
  end
384
384
 
385
385
  it 'parses month-day specs such as MM-DD' do
@@ -408,6 +408,8 @@ describe Date do
408
408
  expect(described_class.parse_spec('2010-09-I', :to)).to eq described_class.parse('2010-09-15')
409
409
  expect(described_class.parse_spec('2010-09-II', :from)).to eq described_class.parse('2010-09-16')
410
410
  expect(described_class.parse_spec('2010-09-II', :to)).to eq described_class.parse('2010-09-30')
411
+ expect(described_class.parse_spec('2010-05-I', :from)).to eq described_class.parse('2010-05-01')
412
+ expect(described_class.parse_spec('2010-05-I', :to)).to eq described_class.parse('2010-05-15')
411
413
  end
412
414
 
413
415
  it 'parses intra-month week specs such as YYYY-MM-i and YYYY-MM-v begin Sunday' do
@@ -753,15 +755,17 @@ describe Date do
753
755
 
754
756
  it 'knows about biweeks' do
755
757
  expect(described_class.parse('2013-11-07').beginning_of_biweek)
756
- .to eq described_class.parse('2013-11-04')
758
+ .to eq described_class.parse('2013-10-28')
757
759
  expect(described_class.parse('2013-11-07').end_of_biweek)
758
- .to eq described_class.parse('2013-11-17')
759
- expect(described_class.parse('2013-03-11')).to be_beginning_of_biweek
760
- expect(described_class.parse('2013-03-24')).to be_end_of_biweek
760
+ .to eq described_class.parse('2013-11-10')
761
+ expect(described_class.parse('2013-03-04')).to be_beginning_of_biweek
762
+ expect(described_class.parse('2013-03-17')).to be_end_of_biweek
761
763
  expect(described_class.parse('2013-12-30').end_of_biweek)
762
- .to eq described_class.parse('2014-01-12')
764
+ .to eq described_class.parse('2014-01-05')
763
765
  expect(described_class.parse('2009-12-30').end_of_biweek)
764
766
  .to eq described_class.parse('2010-01-03')
767
+ expect(described_class.parse('2010-01-03').biweek)
768
+ .to eq described_class.parse('2009-12-31').biweek
765
769
  end
766
770
 
767
771
  it 'knows that a Monday is the beginning of the week' do
@@ -800,10 +804,10 @@ describe Date do
800
804
  it 'knows the beginning and end of bi-week-based chunks' do
801
805
  # First Friday to prior Monday
802
806
  expect(described_class.parse('2013-11-08').beginning_of_chunk(:biweek))
803
- .to eq described_class.parse('2013-11-04')
807
+ .to eq described_class.parse('2013-10-28')
804
808
  # Second Wednesday to 2 prior Monday
805
809
  expect(described_class.parse('2013-11-13').beginning_of_chunk(:biweek))
806
- .to eq described_class.parse('2013-11-04')
810
+ .to eq described_class.parse('2013-11-11')
807
811
  end
808
812
 
809
813
  it 'knows the beginning and end of week-based chunks' do
@@ -980,7 +984,7 @@ describe Date do
980
984
  expect(described_class.parse('2013-11-24').end_of_chunk(:semimonth))
981
985
  .to eq described_class.parse('2013-11-30')
982
986
  expect(described_class.parse('2013-11-08').end_of_chunk(:biweek))
983
- .to eq described_class.parse('2013-11-17')
987
+ .to eq described_class.parse('2013-11-10')
984
988
  expect(described_class.parse('2013-07-04').end_of_chunk(:week))
985
989
  .to eq described_class.parse('2013-07-07')
986
990
  expect {
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: 5.3.0
4
+ version: 5.4.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: 2024-11-10 00:00:00.000000000 Z
11
+ date: 2024-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  requirements: []
117
- rubygems_version: 3.5.23
117
+ rubygems_version: 3.5.22
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: some useful core extensions