fat_core 0.2.5 → 0.2.6

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
  SHA1:
3
- metadata.gz: 4c84245c5d16bd9ed1f877d85b8a4b5f3dd86c2a
4
- data.tar.gz: 17753f85febd4ca6c1cf59f3d51b39068eaf639c
3
+ metadata.gz: 66024aa4a8a016a61e9b00c676c144f2b490eb30
4
+ data.tar.gz: 4036617bcc1deaefcc3f0ad878e14c950e538869
5
5
  SHA512:
6
- metadata.gz: 855688e57b168e2de66da4113c98da40776211468c16766428aa76a090ed901eaf8681d24469ef8df0e893e2afb024f1c45967fa354dddbe0e538d3090444849
7
- data.tar.gz: eeefdbde9edbaa48be5bb4d095d647ebb669d74d3a0411af747e0f9b361849bb81d0b9ce8076f7a252c403043883fba3a13b2e1487bfbeed6c15e83328eb62dc
6
+ metadata.gz: 758f49b0bb0f126c9bbc71ab80f46c292ad12dcf71ab78da171b2f5a74e31974f20641da5a79d8979fccacc87796f3f8a2ea671bfad13fd661dabcbe24e17f8d
7
+ data.tar.gz: 05de2534362aed6b2e9e88e906d34ce01ee49fc24fe04429301247b35d9b3daf0c2c9df4275d51ce83f3f68ff6a4f5f1ea0e34215c466d932b4142b5404386fa
data/fat_core.gemspec CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
+ spec.files.reject! { |fn| fn =~ /^NYSE_closings.pdf/ }
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
20
  spec.require_paths = ["lib"]
data/lib/fat_core/date.rb CHANGED
@@ -651,25 +651,144 @@ class Date
651
651
  # rigged to fall on Monday except Thanksgiving
652
652
 
653
653
  # No moveable feasts in certain months
654
- if [ 6, 7, 8, 10, 12 ].include?(self.month)
655
- false
656
- elsif self.wday == 1
657
- # MLK's Birthday (Third Monday in Jan)
658
- return true if self.nth_wday_in_month?(3, 1, 1)
654
+ return false if [ 6, 7, 8, 10, 12 ].include?(self.month)
655
+
656
+ case month
657
+ when 1
658
+ # MLK's Birthday (Third Monday in Jan) since 1998
659
+ year >= 1998 && nth_wday_in_month?(3, 1, 1)
660
+ when 2
661
+ # Lincoln's birthday until 1953
659
662
  # Washington's Birthday (Third Monday in Feb)
660
- return true if self.nth_wday_in_month?(3, 1, 2)
663
+ (year <= 1953 && month == 2 && day == 12) ||
664
+ (year <= 1970 ? (month == 2 && day == 22)
665
+ : nth_wday_in_month?(3, 1, 2))
666
+ when 3, 4
667
+ # Good Friday
668
+ if self.wday != 5
669
+ false
670
+ else
671
+ # Good Friday, the Friday before Easter, except certain years
672
+ if [1898, 1906, 1907].include?(year)
673
+ false
674
+ else
675
+ (self + 2).easter?
676
+ end
677
+ end
678
+ when 5
661
679
  # Memorial Day (Last Monday in May)
662
- return true if self.nth_wday_in_month?(-1, 1, 5)
680
+ year <= 1970 ? (month == 5 && day == 30) : nth_wday_in_month?(-1, 1, 5)
681
+ when 9
663
682
  # Labor Day (First Monday in Sep)
664
- return true if self.nth_wday_in_month?(1, 1, 9)
665
- # Other Mondays
683
+ nth_wday_in_month?(1, 1, 9)
684
+ when 10
685
+ # Columbus Day (Oct 12) 1909--1953
686
+ year >= 1909 && year <= 1953 && day == 12
687
+ when 11
688
+ if wday == 2
689
+ # Election Day. Until 1968 all Election Days. From 1972 to 1980
690
+ # Election Day in presidential years only. Election Day is the first
691
+ # Tuesday after the first Monday in November.
692
+ first_tuesday = Date.nth_wday_in_year_month(1, 1, year, 11) + 1
693
+ is_election_day = (self == first_tuesday)
694
+ if year <= 1968
695
+ is_election_day
696
+ elsif year <= 1980
697
+ is_election_day && (year % 4 == 0)
698
+ else
699
+ false
700
+ end
701
+ elsif wday == 4
702
+ # Historically Thanksgiving (NYSE closed all day) had been declared to be
703
+ # the last Thursday in November until 1938;
704
+ # the next-to-last Thursday in November from 1939 to 1941
705
+ # (therefore the 3rd Thursday in 1940 and 1941);
706
+ # the last Thursday in November in 1942;
707
+ # the fourth Thursday in November since 1943;
708
+ if year < 1938
709
+ nth_wday_in_month?(-1, 4, 11)
710
+ elsif year <= 1941
711
+ nth_wday_in_month?(3, 4, 11)
712
+ elsif year == 1942
713
+ nth_wday_in_month?(-1, 4, 11)
714
+ else
715
+ nth_wday_in_month?(4, 4, 11)
716
+ end
717
+ elsif day == 11
718
+ # Armistice or Veterans Day. 1918--1921; 1934--1953.
719
+ (year >= 1918 && year <= 1921) || (year >= 1934 && year <= 1953)
720
+ else
721
+ false
722
+ end
723
+ else
666
724
  false
667
- elsif self.wday == 4
668
- # Thanksgiving Day (Fourth Thur in Nov)
669
- self.nth_wday_in_month?(4, 4, 11)
670
- elsif self.wday == 5
671
- # Good Friday, the Friday before Easter
672
- (self + 2).easter?
725
+ end
726
+ end
727
+
728
+ # They NYSE has closed on several occasions outside its normal holiday
729
+ # rules. This detects those dates beginning in 1960. Closing for part of a
730
+ # day is not counted. See http://www1.nyse.com/pdfs/closings.pdf
731
+ def nyse_special_holiday
732
+ return false unless self > Date.parse('1960-01-01')
733
+ case self
734
+ when Date.parse('1961-05-29')
735
+ # Day before Decoaration Day
736
+ true
737
+ when Date.parse('1963-11-25')
738
+ # President Kennedy's funeral
739
+ true
740
+ when Date.parse('1965-12-24')
741
+ # Christmas eve unscheduled for normal holiday
742
+ true
743
+ when Date.parse('1968-02-12')
744
+ # Lincoln birthday
745
+ true
746
+ when Date.parse('1968-04-09')
747
+ # Mourning MLK
748
+ true
749
+ when Date.parse('1968-07-05')
750
+ # Day after Independence Day
751
+ true
752
+ when (Date.parse('1968-06-12')..Date.parse('1968-12-31'))
753
+ # Paperwork crisis (closed on Wednesdays if no other holiday in week)
754
+ wday == 3 && (self - 2).nyse_workday? && (self - 1).nyse_workday? &&
755
+ (self + 1).nyse_workday? && (self + 2).nyse_workday?
756
+ when Date.parse('1969-02-10')
757
+ # Heavy snow
758
+ true
759
+ when Date.parse('1969-05-31')
760
+ # Eisenhower Funeral
761
+ true
762
+ when Date.parse('1969-07-21')
763
+ # Moon landing
764
+ true
765
+ when Date.parse('1972-12-28')
766
+ # Truman Funeral
767
+ true
768
+ when Date.parse('1973-01-25')
769
+ # Johnson Funeral
770
+ true
771
+ when Date.parse('1977-07-14')
772
+ # Electrical blackout NYC
773
+ true
774
+ when Date.parse('1985-09-27')
775
+ # Hurricane Gloria
776
+ true
777
+ when Date.parse('1994-04-27')
778
+ # Nixon Funeral
779
+ true
780
+ when (Date.parse('2001-09-11')..Date.parse('2001-09-14'))
781
+ # 9-11 Attacks
782
+ true
783
+ when (Date.parse('2004-06-11')..Date.parse('2001-09-14'))
784
+ # Reagan Funeral
785
+ true
786
+ when Date.parse('2007-01-02')
787
+ # Observance death of President Ford
788
+ true
789
+ when Date.parse('2012-10-29'), Date.parse('2012-10-30')
790
+ # Hurricane Sandy
791
+ true
673
792
  else
674
793
  false
675
794
  end
@@ -682,6 +801,8 @@ class Date
682
801
  # Is self a fixed holiday
683
802
  return true if self.nyse_fixed_holiday? || self.nyse_moveable_feast?
684
803
 
804
+ return true if nyse_special_holiday
805
+
685
806
  if self.wday == 5
686
807
  # A Friday is a holiday if a fixed-date holiday
687
808
  # would fall on the following Saturday
@@ -1,7 +1,7 @@
1
1
  module FatCore
2
2
  MAJOR = 0
3
3
  MINOR = 2
4
- PATCH = 5
4
+ PATCH = 6
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
7
7
  end
@@ -726,6 +726,23 @@ describe Date do
726
726
  # Weekends are holidays, regardless
727
727
  expect(Date.parse('2014-11-22')).to be_nyse_holiday
728
728
  expect(Date.parse('2014-11-23')).to be_nyse_holiday
729
+
730
+ # 1968 Paperwork Crisis (Closed every Wed unless other holiday in
731
+ # week) from June 12 to December 31, 1968
732
+ expect(Date.parse('1968-06-12')).to be_nyse_holiday
733
+ expect(Date.parse('1968-07-03')).not_to be_nyse_holiday
734
+ expect(Date.parse('1968-08-21')).to be_nyse_holiday
735
+
736
+ # 9-11 Attacks
737
+ expect(Date.parse('2001-09-11')).to be_nyse_holiday
738
+ expect(Date.parse('2001-09-14')).to be_nyse_holiday
739
+
740
+ # Hurricane Sandy
741
+ expect(Date.parse('2012-10-29')).to be_nyse_holiday
742
+ expect(Date.parse('2012-10-30')).to be_nyse_holiday
743
+
744
+ # Death of President Ford
745
+ expect(Date.parse('2007-01-02')).to be_nyse_holiday
729
746
  end
730
747
 
731
748
  it "should know if it is a Federal workday" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fat_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel E. Doherty