ifc_date 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 89ca22bbc889e7505098ed029e28ddde175726a4405e656db1562efecd0fd1dc
4
+ data.tar.gz: 240078f8a04ed2f6c2ba24f5d61417435824443008ec40719a92e5ac186d5f5c
5
+ SHA512:
6
+ metadata.gz: ba2e63ce4cb6e4600069b57479d800b9b20368046c3d3535aece77e4559aeb6c278f2540e11bd7cb0646e34322b4acff6bc2260ad67c6349b48f3d3e74dd6296
7
+ data.tar.gz: f796584f34048013d885d9449a3411ace6c5790fa66d53530366f8fc2812e03ca1f5e56214c379674746ff2d465077f40d992589c26105428ec51c78b1bdd3c7
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-06-08
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in ifc_date.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+ gem 'pry'
12
+
13
+ group :test do
14
+ gem 'activesupport', '>= 7.0.0'
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ifc_date (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (7.0.3)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 1.6, < 2)
12
+ minitest (>= 5.1)
13
+ tzinfo (~> 2.0)
14
+ coderay (1.1.3)
15
+ concurrent-ruby (1.1.10)
16
+ diff-lcs (1.5.0)
17
+ i18n (1.10.0)
18
+ concurrent-ruby (~> 1.0)
19
+ method_source (1.0.0)
20
+ minitest (5.15.0)
21
+ pry (0.14.1)
22
+ coderay (~> 1.1)
23
+ method_source (~> 1.0)
24
+ rake (13.0.6)
25
+ rspec (3.11.0)
26
+ rspec-core (~> 3.11.0)
27
+ rspec-expectations (~> 3.11.0)
28
+ rspec-mocks (~> 3.11.0)
29
+ rspec-core (3.11.0)
30
+ rspec-support (~> 3.11.0)
31
+ rspec-expectations (3.11.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.11.0)
34
+ rspec-mocks (3.11.1)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.11.0)
37
+ rspec-support (3.11.0)
38
+ tzinfo (2.0.4)
39
+ concurrent-ruby (~> 1.0)
40
+
41
+ PLATFORMS
42
+ x86_64-darwin-21
43
+
44
+ DEPENDENCIES
45
+ activesupport (>= 7.0.0)
46
+ ifc_date!
47
+ pry
48
+ rake (~> 13.0)
49
+ rspec (~> 3.0)
50
+
51
+ BUNDLED WITH
52
+ 2.3.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Benjamin ter Kuile
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # IfcDate
2
+
3
+ International Fixed Calendar system. Other name references are Cotsworth and Eastman.
4
+ This implementation is derived from the specs on:
5
+ (https://en.wikipedia.org/wiki/International_Fixed_Calendar)
6
+ And with code inspiraction from:
7
+ (https://github.com/msampathkumar/ifcalendar)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'ifc_date'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install ifc_date
24
+
25
+ ## Usage
26
+
27
+ To create an IfcDate object you specify a day of the year and a year:
28
+ ```ruby
29
+ ifc_date = IfcDate.new(183, 2021)
30
+ ```
31
+ or from a standard `Date` object
32
+ ```ruby
33
+ Date.today.ifc
34
+ ```
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ifc_date.
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,19 @@
1
+ module IfcDateClassMethods
2
+ def is_leap_year?(year)
3
+ return false unless (year % 4).zero?
4
+ return true unless (year % 100).zero?
5
+ (year % 400).zero?
6
+ end
7
+
8
+ def memoize(method_name)
9
+ unmemoized_name = "_unmemoized_#{method_name}"
10
+ instance_var_name = method_name.end_with?('?') ? "@is_#{method_name[0..-2]}" : "@#{method_name}"
11
+ alias_method unmemoized_name, method_name
12
+ define_method method_name do |*args, &block|
13
+ instance_var = instance_variable_get instance_var_name
14
+ return instance_var unless instance_var.nil?
15
+ evaluated_result = send(unmemoized_name, *args, &block)
16
+ instance_variable_set instance_var_name, evaluated_result
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ class Date
2
+ def ifc
3
+ IfcDate.new(yday, year)
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class IfcDate
4
+ VERSION = "0.1.0"
5
+ end
data/lib/ifc_date.rb ADDED
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require_relative 'ifc_date/version'
5
+ require_relative 'ifc_date/ext/to_ifc'
6
+ require_relative 'ifc_date/class_methods'
7
+
8
+ class IfcDate
9
+ class Error < StandardError; end
10
+ extend IfcDateClassMethods
11
+ attr_reader :day_of_year, :year
12
+ alias yday day_of_year
13
+ DAYNAMES = Date::DAYNAMES + ['Starday']
14
+ ABBR_DAYNAMES = Date::ABBR_DAYNAMES + ['Sta']
15
+ MONTHNAMES = Date::MONTHNAMES.dup.insert(6, 'Sol')
16
+ ABBR_MONTHNAMES = Date::ABBR_MONTHNAMES.dup.insert(6, 'Sol')
17
+
18
+ def initialize(day_of_year = nil, year = nil)
19
+ unless year
20
+ date = Date.today
21
+ year = date.year
22
+ day_of_year ||= date.yday
23
+ end
24
+
25
+ day_of_year ||= date.yday
26
+
27
+ @day_of_year = day_of_year
28
+ @year = year
29
+ end
30
+
31
+ memoize def leap_year?
32
+ self.class.is_leap_year?(year)
33
+ end
34
+
35
+ memoize def day_of_year_divmod_seven
36
+ if leap_year? && day_of_year > 169
37
+ (day_of_year - 2).divmod(7)
38
+ else
39
+ (day_of_year - 1).divmod(7)
40
+ end
41
+ end
42
+
43
+ # day_of_year starts from 1,
44
+ # divmod should be zero based
45
+ memoize def day_of_year_divmod_twenty_eight
46
+ if leap_year? && day_of_year > 169
47
+ (day_of_year - 2).divmod(28)
48
+ else
49
+ (day_of_year - 1).divmod(28)
50
+ end
51
+ end
52
+
53
+ memoize def starday?
54
+ if leap_year?
55
+ return true if [169, 366].include?(day_of_year)
56
+ else
57
+ return true if day_of_year == 365
58
+ end
59
+ false
60
+ end
61
+
62
+ memoize def week_of_year
63
+ return 0 if starday?
64
+ day_of_year_divmod_seven[0] + 1
65
+ end
66
+ alias week week_of_year
67
+
68
+ memoize def day_of_week
69
+ return 7 if starday?
70
+ day_of_year_divmod_seven[1]
71
+ end
72
+ alias wday day_of_week
73
+
74
+ def day_of_month
75
+ return 29 if starday?
76
+ #remainder = day_of_year_divmod_twenty_eight[1]
77
+ #remainder.zero? ? 28 : remainder
78
+ day_of_year_divmod_twenty_eight[1] + 1
79
+ end
80
+ alias mday day_of_month
81
+
82
+ # Return the month in index of the year.
83
+ # NOTE Januari will be 1, so different indexing thant the wday
84
+ def month_of_year
85
+ return 13 if day_of_year > 364 # prevent 14
86
+ return 6 if leap_year? && day_of_year == 169
87
+ day_of_year_divmod_twenty_eight[0] + 1
88
+ end
89
+ alias month month_of_year
90
+
91
+ def day_name
92
+ DAYNAMES[day_of_week]
93
+ end
94
+
95
+ def abbr_day_name
96
+ ABBR_DAYNAMES[day_of_week]
97
+ end
98
+
99
+ def month_name
100
+ MONTHNAMES[month_of_year]
101
+ end
102
+
103
+ def abbr_month_name
104
+ ABBR_MONTHNAMES[month_of_year]
105
+ end
106
+ end
data/sig/ifc_date.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module IfcDate
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ifc_date
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Benjamin ter Kuile
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-06-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby implementation of the International Fixed Calendar system. Other
14
+ name references are Cotsworth and Eastman
15
+ email:
16
+ - bterkuile@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rspec"
22
+ - CHANGELOG.md
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - lib/ifc_date.rb
29
+ - lib/ifc_date/class_methods.rb
30
+ - lib/ifc_date/ext/to_ifc.rb
31
+ - lib/ifc_date/version.rb
32
+ - sig/ifc_date.rbs
33
+ homepage: https://gitlab.com/benja-2/ifc_date
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ homepage_uri: https://gitlab.com/benja-2/ifc_date
38
+ source_code_uri: https://gitlab.com/benja-2/ifc_date
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.6.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.3.6
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: International Fixed Calendar system. Other name references are Cotsworth
58
+ and Eastman
59
+ test_files: []