month.rb 0.10.3 → 0.11.1
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/CHANGELOG +66 -0
- data/Gemfile +2 -0
- data/README.md +145 -0
- data/TODO.txt +26 -0
- data/lib/Month/VERSION.rb +1 -1
- data/lib/Month/to_s.rb +3 -2
- data/month.rb.gemspec +43 -0
- data/test/tc_Date_to_month.rb +21 -0
- data/test/tc_Month_begin_date.rb +21 -0
- data/test/tc_Month_beginning.rb +21 -0
- data/test/tc_Month_beginning_of_month.rb +21 -0
- data/test/tc_Month_beginning_of_the_month.rb +21 -0
- data/test/tc_Month_cdate.rb +34 -0
- data/test/tc_Month_cdates.rb +111 -0
- data/test/tc_Month_comparator.rb +17 -0
- data/test/tc_Month_date.rb +34 -0
- data/test/tc_Month_dates.rb +111 -0
- data/test/tc_Month_day.rb +226 -0
- data/test/tc_Month_day_long.rb +152 -0
- data/test/tc_Month_day_short.rb +152 -0
- data/test/tc_Month_day_shortest.rb +152 -0
- data/test/tc_Month_days.rb +21 -0
- data/test/tc_Month_days_in_month.rb +21 -0
- data/test/tc_Month_days_in_the_month.rb +21 -0
- data/test/tc_Month_each_day.rb +21 -0
- data/test/tc_Month_end.rb +21 -0
- data/test/tc_Month_end_date.rb +21 -0
- data/test/tc_Month_end_of_month.rb +21 -0
- data/test/tc_Month_end_of_the_month.rb +21 -0
- data/test/tc_Month_eqlQ.rb +13 -0
- data/test/tc_Month_finish.rb +21 -0
- data/test/tc_Month_finish_date.rb +21 -0
- data/test/tc_Month_finish_of_month.rb +21 -0
- data/test/tc_Month_finish_of_the_month.rb +21 -0
- data/test/tc_Month_initialize.rb +28 -0
- data/test/tc_Month_last.rb +11 -0
- data/test/tc_Month_last_month.rb +11 -0
- data/test/tc_Month_method_missing.rb +116 -0
- data/test/tc_Month_minus.rb +23 -0
- data/test/tc_Month_next.rb +12 -0
- data/test/tc_Month_next_month.rb +12 -0
- data/test/tc_Month_plus.rb +23 -0
- data/test/tc_Month_prev.rb +11 -0
- data/test/tc_Month_prev_month.rb +11 -0
- data/test/tc_Month_previous.rb +11 -0
- data/test/tc_Month_previous_month.rb +11 -0
- data/test/tc_Month_prior.rb +11 -0
- data/test/tc_Month_prior_month.rb +11 -0
- data/test/tc_Month_self.begin_date.rb +46 -0
- data/test/tc_Month_self.beginning.rb +46 -0
- data/test/tc_Month_self.beginning_of_month.rb +46 -0
- data/test/tc_Month_self.beginning_of_the_month.rb +46 -0
- data/test/tc_Month_self.cdate.rb +33 -0
- data/test/tc_Month_self.cdates.rb +325 -0
- data/test/tc_Month_self.date.rb +33 -0
- data/test/tc_Month_self.dates.rb +325 -0
- data/test/tc_Month_self.day.rb +226 -0
- data/test/tc_Month_self.day_long.rb +152 -0
- data/test/tc_Month_self.day_short.rb +152 -0
- data/test/tc_Month_self.day_shortest.rb +152 -0
- data/test/tc_Month_self.days.rb +124 -0
- data/test/tc_Month_self.days_in_month.rb +124 -0
- data/test/tc_Month_self.days_in_the_month.rb +124 -0
- data/test/tc_Month_self.end.rb +21 -0
- data/test/tc_Month_self.end_date.rb +21 -0
- data/test/tc_Month_self.end_of_month.rb +21 -0
- data/test/tc_Month_self.end_of_the_month.rb +21 -0
- data/test/tc_Month_self.finish.rb +21 -0
- data/test/tc_Month_self.finish_date.rb +21 -0
- data/test/tc_Month_self.finish_of_month.rb +21 -0
- data/test/tc_Month_self.finish_of_the_month.rb +21 -0
- data/test/tc_Month_self.from_date.rb +21 -0
- data/test/tc_Month_self.last.rb +47 -0
- data/test/tc_Month_self.last_month.rb +47 -0
- data/test/tc_Month_self.method_missing.rb +227 -0
- data/test/tc_Month_self.next.rb +23 -0
- data/test/tc_Month_self.next_month.rb +23 -0
- data/test/tc_Month_self.now.rb +9 -0
- data/test/tc_Month_self.of.rb +78 -0
- data/test/tc_Month_self.prev.rb +23 -0
- data/test/tc_Month_self.prev_month.rb +23 -0
- data/test/tc_Month_self.previous.rb +23 -0
- data/test/tc_Month_self.previous_month.rb +23 -0
- data/test/tc_Month_self.prior.rb +23 -0
- data/test/tc_Month_self.prior_month.rb +23 -0
- data/test/tc_Month_self.start.rb +21 -0
- data/test/tc_Month_self.start_date.rb +21 -0
- data/test/tc_Month_self.start_of_month.rb +21 -0
- data/test/tc_Month_self.start_of_the_month.rb +21 -0
- data/test/tc_Month_self.succ.rb +23 -0
- data/test/tc_Month_self.succ_month.rb +23 -0
- data/test/tc_Month_self.successor.rb +23 -0
- data/test/tc_Month_self.successor_month.rb +23 -0
- data/test/tc_Month_self.this.rb +23 -0
- data/test/tc_Month_self.to_i.rb +100 -0
- data/test/tc_Month_self.to_long.rb +100 -0
- data/test/tc_Month_self.to_num.rb +100 -0
- data/test/tc_Month_self.to_number.rb +100 -0
- data/test/tc_Month_self.to_short.rb +100 -0
- data/test/tc_Month_self.today.rb +9 -0
- data/test/tc_Month_self.wday.rb +292 -0
- data/test/tc_Month_start.rb +21 -0
- data/test/tc_Month_start_date.rb +21 -0
- data/test/tc_Month_start_of_month.rb +21 -0
- data/test/tc_Month_start_of_the_month.rb +21 -0
- data/test/tc_Month_succ.rb +11 -0
- data/test/tc_Month_succ_month.rb +11 -0
- data/test/tc_Month_successor.rb +11 -0
- data/test/tc_Month_successor_month.rb +11 -0
- data/test/tc_Month_to_date.rb +17 -0
- data/test/tc_Month_to_i.rb +20 -0
- data/test/tc_Month_to_long.rb +20 -0
- data/test/tc_Month_to_num.rb +20 -0
- data/test/tc_Month_to_number.rb +20 -0
- data/test/tc_Month_to_s.rb +40 -0
- data/test/tc_Month_to_short.rb +20 -0
- data/test/tc_gemspec.rb +42 -0
- data/test/ts_Month.rb +14 -0
- metadata +125 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 143cb13b6147f69bcc9547c1e2c322d5a5834b341e7151fd0462279434996bda
|
|
4
|
+
data.tar.gz: a6f735def7556a0944c29badda59dee8aef2941a28c1cc00d499c581ab745d01
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6967cc8e70165761e05b1e2c1cff0f7bf221827c4efe24d649bd156b524a2b10c141420abea46a0930f30a1b0a6316fd68574ca65baf5bc55dd2bfed8402cfa4
|
|
7
|
+
data.tar.gz: d7feb1ad56abe79c3325e125b160c43e86b204afe4c0e2b43593168071439ae87b298fd8cab910d8f1063bd7daa54f6062e42f62ae756f63bbe969614c5f8034
|
data/CHANGELOG
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# CHANGELOG
|
|
2
|
+
|
|
3
|
+
## 20260819
|
|
4
|
+
|
|
5
|
+
0.11.1: Tidy the gemspec, ship what it should, fill in its metadata, and guard it with a test.
|
|
6
|
+
|
|
7
|
+
1. - month.rb.gemspec: spec.date, pinned to '2024-03-06'. A build sets the date; pinning it means every gem built since has claimed to be from that day. impuri removed the same at its 0.9.0.
|
|
8
|
+
2. ~ month.rb.gemspec: spec.files was Dir['lib/**/*.rb'] alone, so the gem shipped the library and nothing else — no CHANGELOG, no README, no Gemfile, not even the gemspec. Now the two Dir globs first and the loose files alphabetically after, as moby and measurand have it.
|
|
9
|
+
3. ~ month.rb.gemspec: /required_ruby_version >= 1.8.6/>= 2.7/, matching impuri. The declared floor was impossible: the gemspec's own <<~ heredoc needs 2.3, and the suite needs a Minitest which needs more than that again.
|
|
10
|
+
4. ~ month.rb.gemspec: /http:\/\/github.com/https:\/\/github.com/.
|
|
11
|
+
5. + month.rb.gemspec: spec.metadata, being bug_tracker_uri, changelog_uri, source_code_uri and documentation_uri. These are the links rubygems shows beside the gem, and with none declared the page offers the homepage alone.
|
|
12
|
+
6. + month.rb.gemspec: spec.require_paths, and a header comment naming the file, as every other file here carries.
|
|
13
|
+
7. + test/tc_gemspec.rb: that the specification validates, that it pins no date, that its version is Month::VERSION, that the four metadata keys are declared and no blob link names a branch other than master, that the loose files ship and not lib alone, and which dependencies it declares. The harness loads test/*.rb by glob, so it needed no registering.
|
|
14
|
+
8. ~ Month::VERSION: /0.11.0/0.11.1/
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
0.11.0: Month#to_s: raise upon an argument it does not know, and correct the examples documenting it.
|
|
18
|
+
|
|
19
|
+
1. ~ Month#to_s: + an else branch raising ArgumentError, naming the argument and the four it accepts. An unknown name length returned nil, and nil from #to_s is worse than most wrong answers: interpolation of the call yields an empty string, so a mistyped format printed nothing at all rather than complaining. This is the breaking change, such as it is — anything relying upon the nil now gets an exception.
|
|
20
|
+
2. ~ Month#to_s: the argument is converted with `month_name_length.to_sym if month_name_length.respond_to?(:to_sym)`, so that a value which cannot be a symbol falls to the same else rather than raising NoMethodError from #to_sym before the case is reached. to_s(3), to_s(nil) and to_s([:long]) now give the same ArgumentError as to_s(:medium), and the message names the original argument rather than the nil the case saw.
|
|
21
|
+
3. ~ Month#to_s: - 'short' from the `when :short, 'short'` clause. The argument is symbolised before the case, so the string could never match there; the string form worked, and still works, by way of the conversion. The clause read as though it handled something it did not.
|
|
22
|
+
4. + test/tc_Month_to_s.rb: that an unknown name length raises, in both symbol and string form, and that an argument which cannot be a symbol raises the same. Verified to have teeth by removing the raise, upon which they fail and nothing else does.
|
|
23
|
+
5. ~ README.md: /Month.new(2011, 1).to_s(:long)/Month.new(1).to_s(:long)/, and likewise for 'long', :short and 'short'. All four stated their output as "January #{Date.today.year}" or "Jan #{Date.today.year}", which is what the year-less form gives and is wrong for a month built with 2011. The receiver was the typo and not the output, and the correct copies of those same four calls with an explicit year already sat below. The examples and the method are one subject, so they move together.
|
|
24
|
+
6. - README.md: a stray end inside the section 3 code fence, left over from an earlier edit and not Ruby anybody could run.
|
|
25
|
+
7. + README.md: blank lines between the year-less, the 2006 and the 2011 groups, so that the pattern the section follows is visible rather than inferred.
|
|
26
|
+
8. ~ Month::VERSION: /0.10.3/0.11.0/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
0.10.3: Populate the .gitignore, which had been committed empty.
|
|
30
|
+
|
|
31
|
+
1. ~ .gitignore: 47 lines, covering gem builds, bundler, RDoc and YARD output, .DS_Store, editor files, the Ruby version managers, test artefacts and .claude. The file existed and was empty, which git-boot creates it as and nothing had since filled in. jira, mercurial, skyhooks, git-boot and git-import-all each took this as a release of its own.
|
|
32
|
+
2. ~ Month::VERSION: /0.10.2/0.10.3/
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
0.10.2: Tidy the CHANGELOG into the form every other gem here uses.
|
|
36
|
+
|
|
37
|
+
1. ~ CHANGELOG.txt --> CHANGELOG, as every other gem here spells it. impuri made the same rename at its 0.9.0.
|
|
38
|
+
2. ~ CHANGELOG: /# 20240306/## 20240306/. A single hash makes the date a top-level heading, level with the file itself, so every date read as a title rather than as a section within one.
|
|
39
|
+
3. ~ CHANGELOG: 20240306 carried two headings, the first holding 0.10.0 and the second 0.10.1 alone, so one day's work read as two. Merged, and impuri met the same duplication at its 0.12.4.
|
|
40
|
+
4. ~ CHANGELOG: the entries reordered newest first. They had been oldest first, which is the reverse of every other gem here and means the version in hand is found at the bottom of a file which only grows.
|
|
41
|
+
5. + CHANGELOG: a # CHANGELOG title, and a blank line between each summary line and its first item, both of which the standard form has and this did not.
|
|
42
|
+
6. ~ Month::VERSION: /0.10.1/0.10.2/
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## 20240306
|
|
46
|
+
|
|
47
|
+
0.10.1: + README.md
|
|
48
|
+
|
|
49
|
+
1. + README.md
|
|
50
|
+
|
|
51
|
+
0.10.0: Use a more conventional structure by removing the Month.rbl directory, get it working again, and create a gem.
|
|
52
|
+
|
|
53
|
+
1. - Month.rbl directory.
|
|
54
|
+
2. + Gemfile
|
|
55
|
+
3. + month.rb.gemspec
|
|
56
|
+
4. - lib/Array/lastX.rb: Not sure why this was here.
|
|
57
|
+
5. - lib/Array/all_but_last.rb: Not sure why this was here.
|
|
58
|
+
6. /ideas.txt/TODO.txt/
|
|
59
|
+
7. ~ lib/Month.rb: Removed date, version, description, and changes to the gemspec and the CHANGELOG.
|
|
60
|
+
8. + CHANGELOG.txt
|
|
61
|
+
9. ~ lib/Month/Constants.rb: - VERSION
|
|
62
|
+
10. + lib/Month/VERSION.rb
|
|
63
|
+
11. /Fixnum/Integer/ (It's been that long!)
|
|
64
|
+
12. /MiniTest/Minitest/ (It's been that long!)
|
|
65
|
+
13. /assert_equal nil,/assert_nil/: Now ready for Minitest 6!
|
|
66
|
+
14. ~ lib/Month.rb: + require 'Date/to_month'
|
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# month.rb
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
This library enables the use of numeric or text representations of months, conversions between month and date objects, the ability to find the number of days and retrieve the dates for all days in a month, and the ability to move forward and back a month at a time.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
```ruby
|
|
11
|
+
gem 'month.rb'
|
|
12
|
+
```
|
|
13
|
+
And then execute:
|
|
14
|
+
```shell
|
|
15
|
+
$ bundle
|
|
16
|
+
```
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
```shell
|
|
19
|
+
$ gem install month.rb
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### 1. Instantiate a month in different ways
|
|
25
|
+
```ruby
|
|
26
|
+
Month.new(2006, 1)
|
|
27
|
+
# => #<Month @year = 2006, @month = 1>
|
|
28
|
+
Month.new(1)
|
|
29
|
+
# => #<Month @year = Date.today.year, @month = 1>
|
|
30
|
+
Month.of('January')
|
|
31
|
+
# => #<Month @year = Date.today.year, @month = 1>
|
|
32
|
+
Month.of('Jan')
|
|
33
|
+
# => #<Month @year = Date.today.year, @month = 1>
|
|
34
|
+
Month.today
|
|
35
|
+
# => #<Month @year = Date.today.year, @month = Date.today.month)>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 2. Convert between month and date objects
|
|
39
|
+
```ruby
|
|
40
|
+
Date.new(2006, 1, 1).to_month
|
|
41
|
+
# => #<Month @year = 2006, @month = 1>
|
|
42
|
+
Month.new(2006, 1).to_date
|
|
43
|
+
# => #<Date @year = 2006, @month = 1, @day = 1>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 3. Convert between numeric and text representations
|
|
47
|
+
```ruby
|
|
48
|
+
Month.new(1).to_number
|
|
49
|
+
# => 1
|
|
50
|
+
Month.new(1).to_short
|
|
51
|
+
# => 'Jan'
|
|
52
|
+
Month.new(1).to_long
|
|
53
|
+
# => 'January'
|
|
54
|
+
|
|
55
|
+
Month.new(2006, 1).to_number
|
|
56
|
+
# => 1
|
|
57
|
+
Month.new(2006, 1).to_short
|
|
58
|
+
# => 'Jan'
|
|
59
|
+
Month.new(2006, 1).to_long
|
|
60
|
+
# => 'January'
|
|
61
|
+
|
|
62
|
+
Month.new(1).to_s
|
|
63
|
+
# => "January #{Date.today.year}"
|
|
64
|
+
Month.new(1).to_s(:long)
|
|
65
|
+
# => "January #{Date.today.year}"
|
|
66
|
+
Month.new(1).to_s('long')
|
|
67
|
+
# => "January #{Date.today.year}"
|
|
68
|
+
Month.new(1).to_s(:short)
|
|
69
|
+
# => "Jan #{Date.today.year}"
|
|
70
|
+
Month.new(1).to_s('short')
|
|
71
|
+
# => "Jan #{Date.today.year}"
|
|
72
|
+
|
|
73
|
+
Month.new(2011, 1).to_s
|
|
74
|
+
# => 'January 2011'
|
|
75
|
+
Month.new(2011, 1).to_s(:long)
|
|
76
|
+
# => 'January 2011'
|
|
77
|
+
Month.new(2011, 1).to_s('long')
|
|
78
|
+
# => 'January 2011'
|
|
79
|
+
Month.new(2011, 1).to_s(:short)
|
|
80
|
+
# => 'Jan 2011'
|
|
81
|
+
Month.new(2011, 1).to_s('short')
|
|
82
|
+
# => 'Jan 2011'
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 4. Compare months
|
|
86
|
+
```ruby
|
|
87
|
+
Month.of('January') == Month.of('January')
|
|
88
|
+
# => true
|
|
89
|
+
Month.of('January') > Month.of('January')
|
|
90
|
+
# => false
|
|
91
|
+
Month.of('February') > Month.of('January')
|
|
92
|
+
# => true
|
|
93
|
+
Month.of('January') < Month.of('February')
|
|
94
|
+
# => true
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 5. Find the dates at the beginning and end of the month
|
|
98
|
+
```ruby
|
|
99
|
+
Month.beginning_of_month(2006, 1)
|
|
100
|
+
# => #<Date @year = 2006, @month = 1, @day = 1>
|
|
101
|
+
Month.end_of_month(2006, 1)
|
|
102
|
+
# => #<Date @year = 2006, @month = 1, @day = 31>
|
|
103
|
+
Month.new(2006, 1).beginning_of_month
|
|
104
|
+
# => #<Date @year = 2006, @month = 1, @day = 1>
|
|
105
|
+
Month.new(2006, 1).end_of_month
|
|
106
|
+
# => #<Date @year = 2006, @month = 1, @day = 31>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 6. Return day numbers or day name for all the days of a week for a given month or just for one day
|
|
110
|
+
```ruby
|
|
111
|
+
Month.dates(2006, 10, day: 'Sunday')
|
|
112
|
+
# => [1, 8, 15, 22, 29]
|
|
113
|
+
Month.new(2011, 1).date('First', 'Monday')
|
|
114
|
+
# => 3
|
|
115
|
+
Month.new(2006, 10).day(1) # Return the day name of first day of the month.
|
|
116
|
+
# => 'Sunday'
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 7. Return the number of days in a month
|
|
120
|
+
```ruby
|
|
121
|
+
Month.days('January')
|
|
122
|
+
# => 31
|
|
123
|
+
Month.of('January').days
|
|
124
|
+
# => 31
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 8. Move forward and backward a month or a year at a time
|
|
128
|
+
```ruby
|
|
129
|
+
Month.new(2011, 1).previous_month
|
|
130
|
+
# => #<Month @year = 2010, @month = 12>
|
|
131
|
+
Month.new(2011, 1).next_month
|
|
132
|
+
# => #<Month @year = 2011, @month = 2>
|
|
133
|
+
Month.new(2011, 1).last_year
|
|
134
|
+
# => #<Month @year = 2010, @month = 2>
|
|
135
|
+
Month.new(2011, 1).next_year
|
|
136
|
+
# => #<Month @year = 2012, @month = 1>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Contributing
|
|
140
|
+
|
|
141
|
+
1. Fork it: https://github.com/thoran/month.rb/fork
|
|
142
|
+
2. Create your feature branch: `git checkout -b my-new-feature`
|
|
143
|
+
3. Commit your changes: `git commit -am 'Add some feature'`
|
|
144
|
+
4. Push to the branch: `git push origin my-new-feature`
|
|
145
|
+
5. Create a new pull request
|
data/TODO.txt
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# 20111205, 20140606
|
|
2
|
+
|
|
3
|
+
Month.new(2).dates('sundays'), Month.new(2).dates('Sundays')
|
|
4
|
+
=> nil
|
|
5
|
+
irb(main):040:0> Month.sunday
|
|
6
|
+
=> [4, 11, 18, 25]
|
|
7
|
+
Month.sundays
|
|
8
|
+
=> [4, 11, 18, 25]
|
|
9
|
+
Month.new(2).dates('sunday'), Month.new(2).dates('Sunday')
|
|
10
|
+
=> [4, 11, 18, 25]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# 20140606
|
|
14
|
+
|
|
15
|
+
Month.from_long('January')
|
|
16
|
+
Month.from_short('Jan')
|
|
17
|
+
Month.from_number(1)
|
|
18
|
+
|
|
19
|
+
Month.parse, can be derived in part from Date.parse
|
|
20
|
+
|
|
21
|
+
Should Month.parse be able to handle all of the what the from_... methods do and therefore they alias Month.parse, or should it hand off to them?
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# 20240306
|
|
25
|
+
|
|
26
|
+
Consider consolidating all the methods into a single file or a lot fewer files anyway, instead of there being one file per method. This stems from some experimentation around how to structure a Ruby library quite some time ago.
|
data/lib/Month/VERSION.rb
CHANGED
data/lib/Month/to_s.rb
CHANGED
|
@@ -8,10 +8,11 @@ require 'Month/to_short'
|
|
|
8
8
|
class Month
|
|
9
9
|
|
|
10
10
|
def to_s(month_name_length = :long)
|
|
11
|
-
case month_name_length.to_sym
|
|
11
|
+
case (month_name_length.to_sym if month_name_length.respond_to?(:to_sym))
|
|
12
12
|
when :long; "#{to_long} #{year}"
|
|
13
|
-
when :short
|
|
13
|
+
when :short; "#{to_short} #{year}"
|
|
14
14
|
when :iso, :iso_8601; "#{year}-" + "%02d" % month
|
|
15
|
+
else; raise ArgumentError, "unknown month name length #{month_name_length.inspect} (expected :long, :short, :iso, or :iso_8601)"
|
|
15
16
|
end
|
|
16
17
|
end
|
|
17
18
|
|
data/month.rb.gemspec
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# month.rb.gemspec
|
|
2
|
+
|
|
3
|
+
require_relative './lib/Month/VERSION'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'month.rb'
|
|
7
|
+
spec.version = Month::VERSION
|
|
8
|
+
|
|
9
|
+
spec.summary = "A library to help working with months."
|
|
10
|
+
spec.description = <<~DESCRIPTION
|
|
11
|
+
This library enables the use of numeric or text representations of months,
|
|
12
|
+
conversions between month and date objects,
|
|
13
|
+
the ability to find the number of days and retrieve the dates for all days in a month,
|
|
14
|
+
and the ability to move forward and back a month at a time.
|
|
15
|
+
DESCRIPTION
|
|
16
|
+
|
|
17
|
+
spec.author = 'thoran'
|
|
18
|
+
spec.email = 'code@thoran.com'
|
|
19
|
+
spec.homepage = 'https://github.com/thoran/month.rb'
|
|
20
|
+
spec.license = 'MIT'
|
|
21
|
+
|
|
22
|
+
spec.metadata = {
|
|
23
|
+
'bug_tracker_uri' => 'https://github.com/thoran/month.rb/issues',
|
|
24
|
+
'changelog_uri' => 'https://github.com/thoran/month.rb/blob/master/CHANGELOG',
|
|
25
|
+
'source_code_uri' => 'https://github.com/thoran/month.rb',
|
|
26
|
+
'documentation_uri' => 'https://github.com/thoran/month.rb/blob/master/README.md',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
spec.required_ruby_version = '>= 2.7'
|
|
30
|
+
spec.require_paths = ['lib']
|
|
31
|
+
|
|
32
|
+
spec.files = [
|
|
33
|
+
Dir['lib/**/*.rb'],
|
|
34
|
+
Dir['test/**/*.rb'],
|
|
35
|
+
'CHANGELOG',
|
|
36
|
+
'Gemfile',
|
|
37
|
+
'month.rb.gemspec',
|
|
38
|
+
'README.md',
|
|
39
|
+
'TODO.txt',
|
|
40
|
+
].flatten
|
|
41
|
+
|
|
42
|
+
spec.add_development_dependency('minitest')
|
|
43
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# test/tc_Month_begin_date.rb
|
|
2
|
+
|
|
3
|
+
class TC_Date_to_month < Minitest::Test
|
|
4
|
+
|
|
5
|
+
def test_Date_to_month
|
|
6
|
+
assert_equal Date.new(2006, 1, 1).to_month, Month.new(2006, 1)
|
|
7
|
+
assert_equal Date.new(2006, 2, 1).to_month, Month.new(2006, 2)
|
|
8
|
+
assert_equal Date.new(2008, 2, 1).to_month, Month.new(2008, 2)
|
|
9
|
+
assert_equal Date.new(2006, 3, 1).to_month, Month.new(2006, 3)
|
|
10
|
+
assert_equal Date.new(2006, 4, 1).to_month, Month.new(2006, 4)
|
|
11
|
+
assert_equal Date.new(2006, 5, 1).to_month, Month.new(2006, 5)
|
|
12
|
+
assert_equal Date.new(2006, 6, 1).to_month, Month.new(2006, 6)
|
|
13
|
+
assert_equal Date.new(2006, 7, 1).to_month, Month.new(2006, 7)
|
|
14
|
+
assert_equal Date.new(2006, 8, 1).to_month, Month.new(2006, 8)
|
|
15
|
+
assert_equal Date.new(2006, 9, 1).to_month, Month.new(2006, 9)
|
|
16
|
+
assert_equal Date.new(2006, 10, 1).to_month, Month.new(2006, 10)
|
|
17
|
+
assert_equal Date.new(2006, 11, 1).to_month, Month.new(2006, 11)
|
|
18
|
+
assert_equal Date.new(2006, 12, 1).to_month, Month.new(2006, 12)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# test/tc_Month_begin_date.rb
|
|
2
|
+
|
|
3
|
+
class TC_Month_begin_date < Minitest::Test
|
|
4
|
+
|
|
5
|
+
def test_begin_date
|
|
6
|
+
assert_equal Date.new(2006, 1, 1), Month.new(2006, 1).begin_date
|
|
7
|
+
assert_equal Date.new(2006, 2, 1), Month.new(2006, 2).begin_date
|
|
8
|
+
assert_equal Date.new(2008, 2, 1), Month.new(2008, 2).begin_date
|
|
9
|
+
assert_equal Date.new(2006, 3, 1), Month.new(2006, 3).begin_date
|
|
10
|
+
assert_equal Date.new(2006, 4, 1), Month.new(2006, 4).begin_date
|
|
11
|
+
assert_equal Date.new(2006, 5, 1), Month.new(2006, 5).begin_date
|
|
12
|
+
assert_equal Date.new(2006, 6, 1), Month.new(2006, 6).begin_date
|
|
13
|
+
assert_equal Date.new(2006, 7, 1), Month.new(2006, 7).begin_date
|
|
14
|
+
assert_equal Date.new(2006, 8, 1), Month.new(2006, 8).begin_date
|
|
15
|
+
assert_equal Date.new(2006, 9, 1), Month.new(2006, 9).begin_date
|
|
16
|
+
assert_equal Date.new(2006, 10, 1), Month.new(2006, 10).begin_date
|
|
17
|
+
assert_equal Date.new(2006, 11, 1), Month.new(2006, 11).begin_date
|
|
18
|
+
assert_equal Date.new(2006, 12, 1), Month.new(2006, 12).begin_date
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# test/tc_Month_beginning.rb
|
|
2
|
+
|
|
3
|
+
class TC_Month_beginning < Minitest::Test
|
|
4
|
+
|
|
5
|
+
def test_beginning
|
|
6
|
+
assert_equal Date.new(2006, 1, 1), Month.new(2006, 1).beginning
|
|
7
|
+
assert_equal Date.new(2006, 2, 1), Month.new(2006, 2).beginning
|
|
8
|
+
assert_equal Date.new(2008, 2, 1), Month.new(2008, 2).beginning
|
|
9
|
+
assert_equal Date.new(2006, 3, 1), Month.new(2006, 3).beginning
|
|
10
|
+
assert_equal Date.new(2006, 4, 1), Month.new(2006, 4).beginning
|
|
11
|
+
assert_equal Date.new(2006, 5, 1), Month.new(2006, 5).beginning
|
|
12
|
+
assert_equal Date.new(2006, 6, 1), Month.new(2006, 6).beginning
|
|
13
|
+
assert_equal Date.new(2006, 7, 1), Month.new(2006, 7).beginning
|
|
14
|
+
assert_equal Date.new(2006, 8, 1), Month.new(2006, 8).beginning
|
|
15
|
+
assert_equal Date.new(2006, 9, 1), Month.new(2006, 9).beginning
|
|
16
|
+
assert_equal Date.new(2006, 10, 1), Month.new(2006, 10).beginning
|
|
17
|
+
assert_equal Date.new(2006, 11, 1), Month.new(2006, 11).beginning
|
|
18
|
+
assert_equal Date.new(2006, 12, 1), Month.new(2006, 12).beginning
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# test/tc_Month_beginning_of_month.rb
|
|
2
|
+
|
|
3
|
+
class TC_Month_beginning_of_month < Minitest::Test
|
|
4
|
+
|
|
5
|
+
def test_beginning_of_month
|
|
6
|
+
assert_equal Date.new(2006, 1, 1), Month.new(2006, 1).beginning_of_month
|
|
7
|
+
assert_equal Date.new(2006, 2, 1), Month.new(2006, 2).beginning_of_month
|
|
8
|
+
assert_equal Date.new(2008, 2, 1), Month.new(2008, 2).beginning_of_month
|
|
9
|
+
assert_equal Date.new(2006, 3, 1), Month.new(2006, 3).beginning_of_month
|
|
10
|
+
assert_equal Date.new(2006, 4, 1), Month.new(2006, 4).beginning_of_month
|
|
11
|
+
assert_equal Date.new(2006, 5, 1), Month.new(2006, 5).beginning_of_month
|
|
12
|
+
assert_equal Date.new(2006, 6, 1), Month.new(2006, 6).beginning_of_month
|
|
13
|
+
assert_equal Date.new(2006, 7, 1), Month.new(2006, 7).beginning_of_month
|
|
14
|
+
assert_equal Date.new(2006, 8, 1), Month.new(2006, 8).beginning_of_month
|
|
15
|
+
assert_equal Date.new(2006, 9, 1), Month.new(2006, 9).beginning_of_month
|
|
16
|
+
assert_equal Date.new(2006, 10, 1), Month.new(2006, 10).beginning_of_month
|
|
17
|
+
assert_equal Date.new(2006, 11, 1), Month.new(2006, 11).beginning_of_month
|
|
18
|
+
assert_equal Date.new(2006, 12, 1), Month.new(2006, 12).beginning_of_month
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# test/tc_Month_beginning_of_the_month.rb
|
|
2
|
+
|
|
3
|
+
class TC_Month_beginning_of_the_month < Minitest::Test
|
|
4
|
+
|
|
5
|
+
def test_beginning_of_the_month
|
|
6
|
+
assert_equal Date.new(2006, 1, 1), Month.new(2006, 1).beginning_of_the_month
|
|
7
|
+
assert_equal Date.new(2006, 2, 1), Month.new(2006, 2).beginning_of_the_month
|
|
8
|
+
assert_equal Date.new(2008, 2, 1), Month.new(2008, 2).beginning_of_the_month
|
|
9
|
+
assert_equal Date.new(2006, 3, 1), Month.new(2006, 3).beginning_of_the_month
|
|
10
|
+
assert_equal Date.new(2006, 4, 1), Month.new(2006, 4).beginning_of_the_month
|
|
11
|
+
assert_equal Date.new(2006, 5, 1), Month.new(2006, 5).beginning_of_the_month
|
|
12
|
+
assert_equal Date.new(2006, 6, 1), Month.new(2006, 6).beginning_of_the_month
|
|
13
|
+
assert_equal Date.new(2006, 7, 1), Month.new(2006, 7).beginning_of_the_month
|
|
14
|
+
assert_equal Date.new(2006, 8, 1), Month.new(2006, 8).beginning_of_the_month
|
|
15
|
+
assert_equal Date.new(2006, 9, 1), Month.new(2006, 9).beginning_of_the_month
|
|
16
|
+
assert_equal Date.new(2006, 10, 1), Month.new(2006, 10).beginning_of_the_month
|
|
17
|
+
assert_equal Date.new(2006, 11, 1), Month.new(2006, 11).beginning_of_the_month
|
|
18
|
+
assert_equal Date.new(2006, 12, 1), Month.new(2006, 12).beginning_of_the_month
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# test/tc_Month_cdate.rb
|
|
2
|
+
|
|
3
|
+
if __FILE__ == $0
|
|
4
|
+
require 'minitest/autorun'
|
|
5
|
+
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
|
|
6
|
+
require 'Month/Constants'
|
|
7
|
+
require 'Month/initialize'
|
|
8
|
+
require 'Month/cdate'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class TC_Month_cdate < Minitest::Test
|
|
12
|
+
|
|
13
|
+
def test_cdate
|
|
14
|
+
assert_equal 3, Month.new(2011, 1).cdate('First', 'Monday')
|
|
15
|
+
assert_equal 14, Month.new(2011, 2).cdate('Second', 'Monday')
|
|
16
|
+
assert_equal 21, Month.new(2011, 3).cdate('Third', 'Monday')
|
|
17
|
+
assert_equal 25, Month.new(2011, 4).cdate('Fourth', 'Monday')
|
|
18
|
+
assert_equal 30, Month.new(2011, 5).cdate('Fifth', 'Monday')
|
|
19
|
+
assert_equal 27, Month.new(2011, 6).cdate('Last', 'Monday')
|
|
20
|
+
assert_equal 18, Month.new(2011, 7).cdate('Second Last', 'Monday')
|
|
21
|
+
assert_equal 15, Month.new(2011, 8).cdate('Third Last', 'Monday')
|
|
22
|
+
assert_equal 5, Month.new(2011, 9).cdate('Fourth Last', 'Monday')
|
|
23
|
+
assert_equal 2, Month.new(2011, 1).cdate('First', 'Sunday')
|
|
24
|
+
assert_equal 13, Month.new(2011, 2).cdate('Second', 'Sunday')
|
|
25
|
+
assert_equal 20, Month.new(2011, 3).cdate('Third', 'Sunday')
|
|
26
|
+
assert_equal 24, Month.new(2011, 4).cdate('Fourth', 'Sunday')
|
|
27
|
+
assert_equal 29, Month.new(2011, 5).cdate('Fifth', 'Sunday')
|
|
28
|
+
assert_equal 26, Month.new(2011, 6).cdate('Last', 'Sunday')
|
|
29
|
+
assert_equal 24, Month.new(2011, 7).cdate('Second Last', 'Sunday')
|
|
30
|
+
assert_equal 14, Month.new(2011, 8).cdate('Third Last', 'Sunday')
|
|
31
|
+
assert_equal 4, Month.new(2011, 9).cdate('Fourth Last', 'Sunday')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# test/tc_Month_cdates.rb
|
|
2
|
+
|
|
3
|
+
if __FILE__ == $0
|
|
4
|
+
require 'minitest/autorun'
|
|
5
|
+
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
|
|
6
|
+
require 'Month/Constants'
|
|
7
|
+
require 'Month/initialize'
|
|
8
|
+
require 'Month/cdates'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class TC_Month_cdates < Minitest::Test
|
|
12
|
+
|
|
13
|
+
def test_cdates
|
|
14
|
+
assert_equal [2, 9, 16, 23, 30], Month.new(2006, 1).cdates('Monday')
|
|
15
|
+
assert_equal [3, 10, 17, 24, 31], Month.new(2006, 1).cdates('Tuesday')
|
|
16
|
+
assert_equal [4, 11, 18, 25], Month.new(2006, 1).cdates('Wednesday')
|
|
17
|
+
assert_equal [5, 12, 19, 26], Month.new(2006, 1).cdates('Thursday')
|
|
18
|
+
assert_equal [6, 13, 20, 27], Month.new(2006, 1).cdates('Friday')
|
|
19
|
+
assert_equal [7, 14, 21, 28], Month.new(2006, 1).cdates('Saturday')
|
|
20
|
+
assert_equal [1, 8, 15, 22, 29], Month.new(2006, 1).cdates('Sunday')
|
|
21
|
+
|
|
22
|
+
assert_equal [6, 13, 20, 27], Month.new(2006, 2).cdates('Monday')
|
|
23
|
+
assert_equal [7, 14, 21, 28], Month.new(2006, 2).cdates('Tuesday')
|
|
24
|
+
assert_equal [1, 8, 15, 22], Month.new(2006, 2).cdates('Wednesday')
|
|
25
|
+
assert_equal [2, 9, 16, 23], Month.new(2006, 2).cdates('Thursday')
|
|
26
|
+
assert_equal [3, 10, 17, 24], Month.new(2006, 2).cdates('Friday')
|
|
27
|
+
assert_equal [4, 11, 18, 25], Month.new(2006, 2).cdates('Saturday')
|
|
28
|
+
assert_equal [5, 12, 19, 26], Month.new(2006, 2).cdates('Sunday')
|
|
29
|
+
|
|
30
|
+
assert_equal [6, 13, 20, 27], Month.new(2006, 3).cdates('Monday')
|
|
31
|
+
assert_equal [7, 14, 21, 28], Month.new(2006, 3).cdates('Tuesday')
|
|
32
|
+
assert_equal [1, 8, 15, 22, 29], Month.new(2006, 3).cdates('Wednesday')
|
|
33
|
+
assert_equal [2, 9, 16, 23, 30], Month.new(2006, 3).cdates('Thursday')
|
|
34
|
+
assert_equal [3, 10, 17, 24, 31], Month.new(2006, 3).cdates('Friday')
|
|
35
|
+
assert_equal [4, 11, 18, 25], Month.new(2006, 3).cdates('Saturday')
|
|
36
|
+
assert_equal [5, 12, 19, 26], Month.new(2006, 3).cdates('Sunday')
|
|
37
|
+
|
|
38
|
+
assert_equal [3, 10, 17, 24], Month.new(2006, 4).cdates('Monday')
|
|
39
|
+
assert_equal [4, 11, 18, 25], Month.new(2006, 4).cdates('Tuesday')
|
|
40
|
+
assert_equal [5, 12, 19, 26], Month.new(2006, 4).cdates('Wednesday')
|
|
41
|
+
assert_equal [6, 13, 20, 27], Month.new(2006, 4).cdates('Thursday')
|
|
42
|
+
assert_equal [7, 14, 21, 28], Month.new(2006, 4).cdates('Friday')
|
|
43
|
+
assert_equal [1, 8, 15, 22, 29], Month.new(2006, 4).cdates('Saturday')
|
|
44
|
+
assert_equal [2, 9, 16, 23, 30], Month.new(2006, 4).cdates('Sunday')
|
|
45
|
+
|
|
46
|
+
assert_equal [1, 8, 15, 22, 29], Month.new(2006, 5).cdates('Monday')
|
|
47
|
+
assert_equal [2, 9, 16, 23, 30], Month.new(2006, 5).cdates('Tuesday')
|
|
48
|
+
assert_equal [3, 10, 17, 24, 31], Month.new(2006, 5).cdates('Wednesday')
|
|
49
|
+
assert_equal [4, 11, 18, 25], Month.new(2006, 5).cdates('Thursday')
|
|
50
|
+
assert_equal [5, 12, 19, 26], Month.new(2006, 5).cdates('Friday')
|
|
51
|
+
assert_equal [6, 13, 20, 27], Month.new(2006, 5).cdates('Saturday')
|
|
52
|
+
assert_equal [7, 14, 21, 28], Month.new(2006, 5).cdates('Sunday')
|
|
53
|
+
|
|
54
|
+
assert_equal [5, 12, 19, 26], Month.new(2006, 6).cdates('Monday')
|
|
55
|
+
assert_equal [6, 13, 20, 27], Month.new(2006, 6).cdates('Tuesday')
|
|
56
|
+
assert_equal [7, 14, 21, 28], Month.new(2006, 6).cdates('Wednesday')
|
|
57
|
+
assert_equal [1, 8, 15, 22, 29], Month.new(2006, 6).cdates('Thursday')
|
|
58
|
+
assert_equal [2, 9, 16, 23, 30], Month.new(2006, 6).cdates('Friday')
|
|
59
|
+
assert_equal [3, 10, 17, 24], Month.new(2006, 6).cdates('Saturday')
|
|
60
|
+
assert_equal [4, 11, 18, 25], Month.new(2006, 6).cdates('Sunday')
|
|
61
|
+
|
|
62
|
+
assert_equal [3, 10, 17, 24, 31], Month.new(2006, 7).cdates('Monday')
|
|
63
|
+
assert_equal [4, 11, 18, 25], Month.new(2006, 7).cdates('Tuesday')
|
|
64
|
+
assert_equal [5, 12, 19, 26], Month.new(2006, 7).cdates('Wednesday')
|
|
65
|
+
assert_equal [6, 13, 20, 27], Month.new(2006, 7).cdates('Thursday')
|
|
66
|
+
assert_equal [7, 14, 21, 28], Month.new(2006, 7).cdates('Friday')
|
|
67
|
+
assert_equal [1, 8, 15, 22, 29], Month.new(2006, 7).cdates('Saturday')
|
|
68
|
+
assert_equal [2, 9, 16, 23, 30], Month.new(2006, 7).cdates('Sunday')
|
|
69
|
+
|
|
70
|
+
assert_equal [7, 14, 21, 28], Month.new(2006, 8).cdates('Monday')
|
|
71
|
+
assert_equal [1, 8, 15, 22, 29], Month.new(2006, 8).cdates('Tuesday')
|
|
72
|
+
assert_equal [2, 9, 16, 23, 30], Month.new(2006, 8).cdates('Wednesday')
|
|
73
|
+
assert_equal [3, 10, 17, 24, 31], Month.new(2006, 8).cdates('Thursday')
|
|
74
|
+
assert_equal [4, 11, 18, 25], Month.new(2006, 8).cdates('Friday')
|
|
75
|
+
assert_equal [5, 12, 19, 26], Month.new(2006, 8).cdates('Saturday')
|
|
76
|
+
assert_equal [6, 13, 20, 27], Month.new(2006, 8).cdates('Sunday')
|
|
77
|
+
|
|
78
|
+
assert_equal [4, 11, 18, 25], Month.new(2006, 9).cdates('Monday')
|
|
79
|
+
assert_equal [5, 12, 19, 26], Month.new(2006, 9).cdates('Tuesday')
|
|
80
|
+
assert_equal [6, 13, 20, 27], Month.new(2006, 9).cdates('Wednesday')
|
|
81
|
+
assert_equal [7, 14, 21, 28], Month.new(2006, 9).cdates('Thursday')
|
|
82
|
+
assert_equal [1, 8, 15, 22, 29], Month.new(2006, 9).cdates('Friday')
|
|
83
|
+
assert_equal [2, 9, 16, 23, 30], Month.new(2006, 9).cdates('Saturday')
|
|
84
|
+
assert_equal [3, 10, 17, 24], Month.new(2006, 9).cdates('Sunday')
|
|
85
|
+
|
|
86
|
+
assert_equal [2, 9, 16, 23, 30], Month.new(2006, 10).cdates('Monday')
|
|
87
|
+
assert_equal [3, 10, 17, 24, 31], Month.new(2006, 10).cdates('Tuesday')
|
|
88
|
+
assert_equal [4, 11, 18, 25], Month.new(2006, 10).cdates('Wednesday')
|
|
89
|
+
assert_equal [5, 12, 19, 26], Month.new(2006, 10).cdates('Thursday')
|
|
90
|
+
assert_equal [6, 13, 20, 27], Month.new(2006, 10).cdates('Friday')
|
|
91
|
+
assert_equal [7, 14, 21, 28], Month.new(2006, 10).cdates('Saturday')
|
|
92
|
+
assert_equal [1, 8, 15, 22, 29], Month.new(2006, 10).cdates('Sunday')
|
|
93
|
+
|
|
94
|
+
assert_equal [6, 13, 20, 27], Month.new(2006, 11).cdates('Monday')
|
|
95
|
+
assert_equal [7, 14, 21, 28], Month.new(2006, 11).cdates('Tuesday')
|
|
96
|
+
assert_equal [1, 8, 15, 22, 29], Month.new(2006, 11).cdates('Wednesday')
|
|
97
|
+
assert_equal [2, 9, 16, 23, 30], Month.new(2006, 11).cdates('Thursday')
|
|
98
|
+
assert_equal [3, 10, 17, 24], Month.new(2006, 11).cdates('Friday')
|
|
99
|
+
assert_equal [4, 11, 18, 25], Month.new(2006, 11).cdates('Saturday')
|
|
100
|
+
assert_equal [5, 12, 19, 26], Month.new(2006, 11).cdates('Sunday')
|
|
101
|
+
|
|
102
|
+
assert_equal [4, 11, 18, 25], Month.new(2006, 12).cdates('Monday')
|
|
103
|
+
assert_equal [5, 12, 19, 26], Month.new(2006, 12).cdates('Tuesday')
|
|
104
|
+
assert_equal [6, 13, 20, 27], Month.new(2006, 12).cdates('Wednesday')
|
|
105
|
+
assert_equal [7, 14, 21, 28], Month.new(2006, 12).cdates('Thursday')
|
|
106
|
+
assert_equal [1, 8, 15, 22, 29], Month.new(2006, 12).cdates('Friday')
|
|
107
|
+
assert_equal [2, 9, 16, 23, 30], Month.new(2006, 12).cdates('Saturday')
|
|
108
|
+
assert_equal [3, 10, 17, 24, 31], Month.new(2006, 12).cdates('Sunday')
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# test/tc_Month_comparator.rb
|
|
2
|
+
|
|
3
|
+
class TC_Month_comparator < Minitest::Test
|
|
4
|
+
|
|
5
|
+
def test_equivalence
|
|
6
|
+
assert_equal true, Month.new(2011, 1) == Month.new(2011, 1)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def test_greater_than
|
|
10
|
+
assert_equal true, Month.new(2011, 2) > Month.new(2011, 1)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_less_than
|
|
14
|
+
assert_equal true, Month.new(2011, 1) < Month.new(2011, 2)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# test/tc_Month_date.rb
|
|
2
|
+
|
|
3
|
+
if __FILE__ == $0
|
|
4
|
+
require 'minitest/autorun'
|
|
5
|
+
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
|
|
6
|
+
require 'Month/Constants'
|
|
7
|
+
require 'Month/initialize'
|
|
8
|
+
require 'Month/date'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class TC_Month_date < Minitest::Test
|
|
12
|
+
|
|
13
|
+
def test_date
|
|
14
|
+
assert_equal 3, Month.new(2011, 1).date('First', 'Monday')
|
|
15
|
+
assert_equal 14, Month.new(2011, 2).date('Second', 'Monday')
|
|
16
|
+
assert_equal 21, Month.new(2011, 3).date('Third', 'Monday')
|
|
17
|
+
assert_equal 25, Month.new(2011, 4).date('Fourth', 'Monday')
|
|
18
|
+
assert_equal 30, Month.new(2011, 5).date('Fifth', 'Monday')
|
|
19
|
+
assert_equal 27, Month.new(2011, 6).date('Last', 'Monday')
|
|
20
|
+
assert_equal 18, Month.new(2011, 7).date('Second Last', 'Monday')
|
|
21
|
+
assert_equal 15, Month.new(2011, 8).date('Third Last', 'Monday')
|
|
22
|
+
assert_equal 5, Month.new(2011, 9).date('Fourth Last', 'Monday')
|
|
23
|
+
assert_equal 2, Month.new(2011, 1).date('First', 'Sunday')
|
|
24
|
+
assert_equal 13, Month.new(2011, 2).date('Second', 'Sunday')
|
|
25
|
+
assert_equal 20, Month.new(2011, 3).date('Third', 'Sunday')
|
|
26
|
+
assert_equal 24, Month.new(2011, 4).date('Fourth', 'Sunday')
|
|
27
|
+
assert_equal 29, Month.new(2011, 5).date('Fifth', 'Sunday')
|
|
28
|
+
assert_equal 26, Month.new(2011, 6).date('Last', 'Sunday')
|
|
29
|
+
assert_equal 24, Month.new(2011, 7).date('Second Last', 'Sunday')
|
|
30
|
+
assert_equal 14, Month.new(2011, 8).date('Third Last', 'Sunday')
|
|
31
|
+
assert_equal 4, Month.new(2011, 9).date('Fourth Last', 'Sunday')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|