timeboss 0.0.10 → 0.2.2
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/.gitignore +5 -3
- data/.yardopts +1 -0
- data/README.md +12 -5
- data/bin/tbsh +1 -1
- data/lib/timeboss.rb +4 -0
- data/lib/timeboss/calendar.rb +21 -0
- data/lib/timeboss/calendar/day.rb +9 -3
- data/lib/timeboss/calendar/half.rb +6 -2
- data/lib/timeboss/calendar/month.rb +6 -2
- data/lib/timeboss/calendar/period.rb +25 -11
- data/lib/timeboss/calendar/quarter.rb +6 -2
- data/lib/timeboss/calendar/support/formatter.rb +4 -2
- data/lib/timeboss/calendar/support/month_basis.rb +1 -0
- data/lib/timeboss/calendar/support/{month_based.rb → monthly_unit.rb} +5 -1
- data/lib/timeboss/calendar/support/navigable.rb +24 -1
- data/lib/timeboss/calendar/support/shiftable.rb +218 -28
- data/lib/timeboss/calendar/support/translatable.rb +92 -0
- data/lib/timeboss/calendar/support/unit.rb +27 -0
- data/lib/timeboss/calendar/waypoints.rb +5 -55
- data/lib/timeboss/calendar/waypoints/absolute.rb +113 -0
- data/lib/timeboss/calendar/waypoints/relative.rb +267 -0
- data/lib/timeboss/calendar/week.rb +11 -0
- data/lib/timeboss/calendar/year.rb +5 -5
- data/lib/timeboss/calendars.rb +15 -0
- data/lib/timeboss/calendars/gregorian.rb +28 -0
- data/lib/timeboss/version.rb +1 -1
- data/spec/calendar/support/{month_based_spec.rb → monthly_unit_spec.rb} +13 -7
- data/spec/calendar/week_spec.rb +6 -1
- data/spec/calendars/broadcast_spec.rb +7 -7
- data/spec/calendars/gregorian_spec.rb +685 -0
- data/timeboss.gemspec +1 -0
- metadata +27 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d4c953bb1ef449bdc7d37f0ac3061da752b28a9f4df8c1901f9507c447ac89b
|
4
|
+
data.tar.gz: 752abd38f0afee607b6529894eec4189dfbbc462f5a27ddb4a6238720db35b4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1d04714bcb3514b386fda20f1aaad42f1db96382719848ef9ee5cf889b5c855a26bbb6c6039f50e08ce2484194924ceb8a2ee32f0242b1e3bbc928a9156a0b8
|
7
|
+
data.tar.gz: 1662c699fc80d9b37744a2f7f4fffa5d72e64d912bab4e19b1d113ba466a16201c003e32b26d1d8697da8c2feb21d4e16be344bc2bacdb2358f2a46ed6646c49
|
data/.gitignore
CHANGED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--protected lib/**/*.rb
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# TimeBoss [](https://travis-ci.com/kevinstuffandthings/timeboss) [](https://badge.fury.io/rb/timeboss)
|
2
|
-
|
2
|
+
|
3
|
+
A gem providing convenient navigation of the [Broadcast Calendar](https://en.wikipedia.org/wiki/Broadcast_calendar), the standard Gregorian calendar, and is easily extensible to support multiple financial calendars.
|
4
|
+
|
3
5
|
Originally developed for [Simulmedia](https://simulmedia.com).
|
4
6
|
|
5
7
|
## Installation
|
@@ -23,7 +25,7 @@ $ gem install timeboss
|
|
23
25
|
```
|
24
26
|
|
25
27
|
## Usage
|
26
|
-
Supports `year`, `half`, `quarter`, `month`, `week
|
28
|
+
Supports `year`, `half`, `quarter`, `month`, `week` (non-gregorian calendars only), and `day`.
|
27
29
|
|
28
30
|
Prepare your calendar for use:
|
29
31
|
|
@@ -62,7 +64,7 @@ calendar.years_back(2).map { |y| y.start_date.to_s } # run in 2020
|
|
62
64
|
calendar.months_ago(3).name # run in 2020M7
|
63
65
|
# => "2020M4"
|
64
66
|
|
65
|
-
calendar.
|
67
|
+
calendar.weeks_ahead(3).name # run in 2020W29
|
66
68
|
# => "2020W32"
|
67
69
|
```
|
68
70
|
|
@@ -131,11 +133,16 @@ period = calendar.parse('2020W3..2020Q1')
|
|
131
133
|
# => "2020W3 .. 2020Q1: from 2020-01-13 thru 2020-03-29 (current=false)"
|
132
134
|
```
|
133
135
|
|
134
|
-
The examples above are just samples. Try different periods, operators, etc.
|
136
|
+
The examples above are just samples. Try different periods, operators, etc. All of the non-week-based operations will work similarly on the `TimeBoss::Calendars::Gregorian` calendar.
|
135
137
|
|
136
138
|
### Shell
|
137
139
|
To open an IRB shell for the broadcast calendar, use the `tbsh` executable, or the `timeboss:calendars:broadcast:shell` rake task.
|
138
|
-
|
140
|
+
|
141
|
+
For the Gregorian calendar (or any other implemented calendars), supply the name on the command line.
|
142
|
+
- `tbsh gregorian`
|
143
|
+
- `rake timeboss:calendars:gregorian:shell`
|
144
|
+
|
145
|
+
You will find yourself in the context of an instantiated `TimeBoss::Calendar` object:
|
139
146
|
|
140
147
|
```bash
|
141
148
|
$ tbsh
|
data/bin/tbsh
CHANGED
data/lib/timeboss.rb
CHANGED
data/lib/timeboss/calendar.rb
CHANGED
@@ -9,16 +9,37 @@ require_relative './calendar/support/month_basis'
|
|
9
9
|
module TimeBoss
|
10
10
|
class Calendar
|
11
11
|
include Waypoints
|
12
|
+
|
13
|
+
# @!method parse
|
14
|
+
# Parse an identifier into a unit or period.
|
15
|
+
# Valid identifiers can include simple units (like "2020Q3", "2020M8W3", "last_quarter"),
|
16
|
+
# mathematical expressions (like "this_month+6"),
|
17
|
+
# or period expressions (like "2020W1..2020W8", "this_quarter-2..next_quarter")
|
18
|
+
# @param identifier [String]
|
19
|
+
# @return [Support::Unit, Period]
|
20
|
+
|
12
21
|
delegate :parse, to: :parser
|
13
22
|
|
23
|
+
# Get a name by which this calendar can be referenced.
|
24
|
+
# @return [String]
|
14
25
|
def name
|
15
26
|
self.class.to_s.demodulize.underscore
|
16
27
|
end
|
17
28
|
|
29
|
+
# Get a friendly title for this calendar.
|
30
|
+
# @return [String]
|
18
31
|
def title
|
19
32
|
name.titleize
|
20
33
|
end
|
21
34
|
|
35
|
+
# Can this calendar support weeks?
|
36
|
+
# For custom calendars, this value can generally not be overridden.
|
37
|
+
# But for calendars like our Gregorian implementation, weeks are irrelevant, and should be suppressed.
|
38
|
+
# @return [Boolean]
|
39
|
+
def supports_weeks?
|
40
|
+
true
|
41
|
+
end
|
42
|
+
|
22
43
|
protected
|
23
44
|
|
24
45
|
attr_reader :basis
|
@@ -8,22 +8,28 @@ module TimeBoss
|
|
8
8
|
super(calendar, start_date, start_date)
|
9
9
|
end
|
10
10
|
|
11
|
+
# Get a simple representation of this day.
|
12
|
+
# @return [String] (e.g. "2020-08-03")
|
11
13
|
def name
|
12
14
|
start_date.to_s
|
13
15
|
end
|
14
16
|
|
17
|
+
# Get a "pretty" representation of this day.
|
18
|
+
# @return [String] (e.g. "August 3, 2020")
|
15
19
|
def title
|
16
20
|
start_date.strftime('%B %-d, %Y')
|
17
21
|
end
|
18
22
|
|
19
|
-
|
20
|
-
name
|
21
|
-
end
|
23
|
+
alias_method :to_s, :name
|
22
24
|
|
25
|
+
# Get the index of this day within its containing year.
|
26
|
+
# @return [Integer]
|
23
27
|
def index
|
24
28
|
@_index ||= (start_date - year.start_date).to_i + 1
|
25
29
|
end
|
26
30
|
|
31
|
+
# Get the year number for this day.
|
32
|
+
# @return [Integer] (e.g. 2020)
|
27
33
|
def year_index
|
28
34
|
@_year_index ||= year.year_index
|
29
35
|
end
|
@@ -1,15 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require_relative './support/
|
2
|
+
require_relative './support/monthly_unit'
|
3
3
|
|
4
4
|
module TimeBoss
|
5
5
|
class Calendar
|
6
|
-
class Half < Support::
|
6
|
+
class Half < Support::MonthlyUnit
|
7
7
|
NUM_MONTHS = 6
|
8
8
|
|
9
|
+
# Get a simple representation of this half.
|
10
|
+
# @return [String] (e.g. "2020H2")
|
9
11
|
def name
|
10
12
|
"#{year_index}H#{index}"
|
11
13
|
end
|
12
14
|
|
15
|
+
# Get a "pretty" representation of this half.
|
16
|
+
# @return [String] (e.g. "H2 2020")
|
13
17
|
def title
|
14
18
|
"H#{index} #{year_index}"
|
15
19
|
end
|
@@ -1,15 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require_relative './support/
|
2
|
+
require_relative './support/monthly_unit'
|
3
3
|
|
4
4
|
module TimeBoss
|
5
5
|
class Calendar
|
6
|
-
class Month < Support::
|
6
|
+
class Month < Support::MonthlyUnit
|
7
7
|
NUM_MONTHS = 1
|
8
8
|
|
9
|
+
# Get a simple representation of this month.
|
10
|
+
# @return [String] (e.g. "2020M8")
|
9
11
|
def name
|
10
12
|
"#{year_index}M#{index}"
|
11
13
|
end
|
12
14
|
|
15
|
+
# Get a "pretty" representation of this month.
|
16
|
+
# @return [String] (e.g. "August 2020")
|
13
17
|
def title
|
14
18
|
"#{Date::MONTHNAMES[index]} #{year_index}"
|
15
19
|
end
|
@@ -3,9 +3,29 @@ module TimeBoss
|
|
3
3
|
class Calendar
|
4
4
|
class Period
|
5
5
|
attr_reader :begin, :end
|
6
|
+
|
7
|
+
# @!method start_date
|
8
|
+
# Get the start date of this period.
|
9
|
+
# @return [Date]
|
6
10
|
delegate :start_date, to: :begin
|
11
|
+
|
12
|
+
# @!method end_date
|
13
|
+
# Get the end date of this period.
|
14
|
+
# @return [Date]
|
7
15
|
delegate :end_date, to: :end
|
8
16
|
|
17
|
+
# @!method name
|
18
|
+
# Get a simple representation of this period.
|
19
|
+
# @return [String]
|
20
|
+
|
21
|
+
# @!method title
|
22
|
+
# Get a "pretty" representation of this period.
|
23
|
+
# @return [String]
|
24
|
+
|
25
|
+
# @!method to_s
|
26
|
+
# Get a stringified representation of this period.
|
27
|
+
# @return [String]
|
28
|
+
|
9
29
|
%i[name title to_s].each do |message|
|
10
30
|
define_method(message) do
|
11
31
|
text = self.begin.send(message)
|
@@ -14,7 +34,7 @@ module TimeBoss
|
|
14
34
|
end
|
15
35
|
end
|
16
36
|
|
17
|
-
%w[week month quarter half year].each do |size|
|
37
|
+
%w[day week month quarter half year].each do |size|
|
18
38
|
define_method(size.pluralize) do
|
19
39
|
entry = calendar.send("#{size}_for", self.begin.start_date)
|
20
40
|
build_entries entry
|
@@ -27,20 +47,14 @@ module TimeBoss
|
|
27
47
|
end
|
28
48
|
end
|
29
49
|
|
50
|
+
# Does this period cover the current date?
|
51
|
+
# @return [Boolean]
|
30
52
|
def current?
|
31
53
|
to_range.include?(Date.today)
|
32
54
|
end
|
33
55
|
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
def day
|
39
|
-
entries = days
|
40
|
-
return nil unless entries.length == 1
|
41
|
-
entries.first
|
42
|
-
end
|
43
|
-
|
56
|
+
# Express this period as a date range.
|
57
|
+
# @return [Range<Date, Date>]
|
44
58
|
def to_range
|
45
59
|
@_to_range ||= start_date .. end_date
|
46
60
|
end
|
@@ -1,15 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require_relative './support/
|
2
|
+
require_relative './support/monthly_unit'
|
3
3
|
|
4
4
|
module TimeBoss
|
5
5
|
class Calendar
|
6
|
-
class Quarter < Support::
|
6
|
+
class Quarter < Support::MonthlyUnit
|
7
7
|
NUM_MONTHS = 3
|
8
8
|
|
9
|
+
# Get a simple representation of this quarter.
|
10
|
+
# @return [String] (e.g. "2020Q3")
|
9
11
|
def name
|
10
12
|
"#{year_index}Q#{index}"
|
11
13
|
end
|
12
14
|
|
15
|
+
# Get a "pretty" representation of this quarter.
|
16
|
+
# @return [String] (e.g. "Q3 2020")
|
13
17
|
def title
|
14
18
|
"Q#{index} #{year_index}"
|
15
19
|
end
|
@@ -1,18 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require_relative './
|
2
|
+
require_relative './translatable'
|
3
3
|
|
4
4
|
module TimeBoss
|
5
5
|
class Calendar
|
6
6
|
module Support
|
7
7
|
private
|
8
8
|
|
9
|
+
# The formatter is responsible for the implementation of name formatting for a unit.
|
9
10
|
class Formatter
|
10
|
-
PERIODS =
|
11
|
+
PERIODS = Translatable::PERIODS.reverse.map(&:to_sym).drop(1)
|
11
12
|
attr_reader :unit, :periods
|
12
13
|
|
13
14
|
def initialize(unit, periods)
|
14
15
|
@unit = unit
|
15
16
|
@periods = PERIODS & periods.map(&:to_sym).push(unit.class.type.to_sym)
|
17
|
+
@periods -= [:week] unless unit.calendar.supports_weeks?
|
16
18
|
end
|
17
19
|
|
18
20
|
def to_s
|
@@ -4,7 +4,7 @@ require_relative './unit'
|
|
4
4
|
module TimeBoss
|
5
5
|
class Calendar
|
6
6
|
module Support
|
7
|
-
class
|
7
|
+
class MonthlyUnit < Unit
|
8
8
|
attr_reader :year_index, :index
|
9
9
|
|
10
10
|
def initialize(calendar, year_index, index, start_date, end_date)
|
@@ -13,10 +13,14 @@ module TimeBoss
|
|
13
13
|
@index = index
|
14
14
|
end
|
15
15
|
|
16
|
+
# Get a stringified representation of this unit.
|
17
|
+
# @return [String] (e.g. "2020Q3: 2020-06-29 thru 2020-09-27")
|
16
18
|
def to_s
|
17
19
|
"#{name}: #{start_date} thru #{end_date}"
|
18
20
|
end
|
19
21
|
|
22
|
+
# Get a list of weeks contained within this period.
|
23
|
+
# @return [Array<Week>]
|
20
24
|
def weeks
|
21
25
|
base = calendar.year(year_index)
|
22
26
|
num_weeks = (((base.end_date - base.start_date) + 1) / 7.0).to_i
|
@@ -3,24 +3,47 @@ module TimeBoss
|
|
3
3
|
class Calendar
|
4
4
|
module Support
|
5
5
|
module Navigable
|
6
|
+
# @overload previous
|
7
|
+
# Fetch the previous unit relative to this unit.
|
8
|
+
# @return [Unit]
|
9
|
+
# @overload previous(value)
|
10
|
+
# Fetch some previous number of units relative to this unit
|
11
|
+
# @param quantity [Integer]
|
12
|
+
# @return [Array<Unit>]
|
6
13
|
def previous(quantity = nil)
|
7
14
|
return down if quantity.nil?
|
8
15
|
gather(:previous, quantity).reverse
|
9
16
|
end
|
10
17
|
|
18
|
+
# @overload next
|
19
|
+
# Fetch the next unit relative to this unit.
|
20
|
+
# @return [Unit]
|
21
|
+
# @overload next(value)
|
22
|
+
# Fetch some next number of units relative to this unit
|
23
|
+
# @param quantity [Integer]
|
24
|
+
# @return [Array<Unit>]
|
11
25
|
def next(quantity = nil)
|
12
26
|
return up if quantity.nil?
|
13
27
|
gather(:next, quantity)
|
14
28
|
end
|
15
29
|
|
30
|
+
# Fetch the unit some number of units prior to this unit.
|
31
|
+
# @param quantity [Integer]
|
32
|
+
# @return [Unit]
|
16
33
|
def ago(quantity)
|
17
34
|
previous(quantity + 1).first
|
18
35
|
end
|
19
36
|
|
20
|
-
|
37
|
+
# Fetch the unit some number of units after this unit.
|
38
|
+
# @param quantity [Integer]
|
39
|
+
# @return [Unit]
|
40
|
+
def ahead(quantity)
|
21
41
|
self.next(quantity + 1).last
|
22
42
|
end
|
23
43
|
|
44
|
+
# Fetch a list of units from this unit until some date.
|
45
|
+
# @param end_date [Date]
|
46
|
+
# @return [Array<Unit>]
|
24
47
|
def until(end_date)
|
25
48
|
entry = self
|
26
49
|
[entry].tap do |entries|
|
@@ -3,48 +3,238 @@ module TimeBoss
|
|
3
3
|
class Calendar
|
4
4
|
module Support
|
5
5
|
module Shiftable
|
6
|
-
PERIODS
|
7
|
-
|
8
|
-
PERIODS.each do |period|
|
6
|
+
Support::Translatable::PERIODS.each do |period|
|
9
7
|
periods = period.pluralize
|
10
8
|
|
11
|
-
define_method
|
12
|
-
calendar.send("#{periods}_for", self)
|
13
|
-
end
|
14
|
-
|
15
|
-
define_method period do
|
16
|
-
entries = send(periods)
|
17
|
-
return nil unless entries.length == 1
|
18
|
-
entries.first
|
19
|
-
end
|
20
|
-
|
21
|
-
define_method "in_#{period}" do
|
9
|
+
define_method("in_#{period}") do
|
22
10
|
base = send(periods)
|
23
11
|
return unless base.length == 1
|
24
12
|
base.first.send(self.class.type.to_s.pluralize).find_index { |p| p == self } + 1
|
25
13
|
end
|
26
14
|
|
27
|
-
define_method
|
15
|
+
define_method("#{periods}_ago") do |offset|
|
28
16
|
base_offset = send("in_#{period}") or return
|
29
17
|
(calendar.send("this_#{period}") - offset).send(self.class.type.to_s.pluralize)[base_offset - 1]
|
30
18
|
end
|
31
19
|
|
32
|
-
define_method "
|
33
|
-
send("#{periods}_ago", 1)
|
34
|
-
end
|
20
|
+
define_method("#{periods}_ahead") { |o| send("#{periods}_ago", o * -1) }
|
35
21
|
|
36
|
-
define_method
|
37
|
-
|
38
|
-
|
22
|
+
define_method("last_#{period}") { send("#{periods}_ago", 1) }
|
23
|
+
define_method("this_#{period}") { send("#{periods}_ago", 0) }
|
24
|
+
define_method("next_#{period}") { send("#{periods}_ahead", 1) }
|
25
|
+
end
|
39
26
|
|
40
|
-
|
41
|
-
|
42
|
-
|
27
|
+
alias_method :yesterday, :last_day
|
28
|
+
alias_method :today, :this_day
|
29
|
+
alias_method :tomorrow, :next_day
|
43
30
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
31
|
+
#
|
32
|
+
# i hate this
|
33
|
+
#
|
34
|
+
|
35
|
+
### Days
|
36
|
+
|
37
|
+
# @!method in_day
|
38
|
+
# Get the index within the day that this unit falls in.
|
39
|
+
# Returns nil if no single day can be identified.
|
40
|
+
# @return [Integer, nil]
|
41
|
+
|
42
|
+
# @!method days_ago
|
43
|
+
# Get the index-relative day some number of days ago.
|
44
|
+
# Returns nil if no single day can be identified.
|
45
|
+
# @param offset [Integer] the number of days back to shift this period
|
46
|
+
# @return [Calendar::Day, nil]
|
47
|
+
|
48
|
+
# @!method days_ahead
|
49
|
+
# Get the index-relative day some number of days ahead.
|
50
|
+
# Returns nil if no single day can be identified.
|
51
|
+
# @param offset [Integer] the number of days forward to shift this period
|
52
|
+
# @return [Calendar::Day, nil]
|
53
|
+
|
54
|
+
# @!method last_day
|
55
|
+
# Get the index-relative day 1 day ago.
|
56
|
+
# Returns nil if no single day can be identified.
|
57
|
+
# @return [Calendar::Day, nil]
|
58
|
+
|
59
|
+
# @!method this_day
|
60
|
+
# Get the index-relative day for this day.
|
61
|
+
# Returns nil if no single day can be identified.
|
62
|
+
# @return [Calendar::Day, nil]
|
63
|
+
|
64
|
+
# @!method next_day
|
65
|
+
# Get the index-relative day 1 day forward.
|
66
|
+
# Returns nil if no single day can be identified.
|
67
|
+
# @return [Calendar::Day, nil]
|
68
|
+
|
69
|
+
### Weeks
|
70
|
+
|
71
|
+
# @!method in_week
|
72
|
+
# Get the index within the week that this unit falls in.
|
73
|
+
# Returns nil if no single week can be identified.
|
74
|
+
# @return [Integer, nil]
|
75
|
+
|
76
|
+
# @!method weeks_ago
|
77
|
+
# Get the index-relative week some number of weeks ago.
|
78
|
+
# Returns nil if no single week can be identified.
|
79
|
+
# @param offset [Integer] the number of weeks back to shift this period
|
80
|
+
# @return [Calendar::Week, nil]
|
81
|
+
|
82
|
+
# @!method weeks_ahead
|
83
|
+
# Get the index-relative week some number of weeks ahead.
|
84
|
+
# Returns nil if no single week can be identified.
|
85
|
+
# @param offset [Integer] the number of weeks forward to shift this period
|
86
|
+
# @return [Calendar::Week, nil]
|
87
|
+
|
88
|
+
# @!method last_week
|
89
|
+
# Get the index-relative week 1 week ago.
|
90
|
+
# Returns nil if no single week can be identified.
|
91
|
+
# @return [Calendar::Week, nil]
|
92
|
+
|
93
|
+
# @!method this_week
|
94
|
+
# Get the index-relative week for this week.
|
95
|
+
# Returns nil if no single week can be identified.
|
96
|
+
# @return [Calendar::Week, nil]
|
97
|
+
|
98
|
+
# @!method next_week
|
99
|
+
# Get the index-relative week 1 week forward.
|
100
|
+
# Returns nil if no single week can be identified.
|
101
|
+
# @return [Calendar::Week, nil]
|
102
|
+
|
103
|
+
### Months
|
104
|
+
|
105
|
+
# @!method in_month
|
106
|
+
# Get the index within the month that this unit falls in.
|
107
|
+
# Returns nil if no single month can be identified.
|
108
|
+
# @return [Integer, nil]
|
109
|
+
|
110
|
+
# @!method months_ago
|
111
|
+
# Get the index-relative month some number of months ago.
|
112
|
+
# Returns nil if no single month can be identified.
|
113
|
+
# @param offset [Integer] the number of months back to shift this period
|
114
|
+
# @return [Calendar::Month, nil]
|
115
|
+
|
116
|
+
# @!method months_ahead
|
117
|
+
# Get the index-relative month some number of months ahead.
|
118
|
+
# Returns nil if no single month can be identified.
|
119
|
+
# @param offset [Integer] the number of months forward to shift this period
|
120
|
+
# @return [Calendar::Month, nil]
|
121
|
+
|
122
|
+
# @!method last_month
|
123
|
+
# Get the index-relative month 1 month ago.
|
124
|
+
# Returns nil if no single month can be identified.
|
125
|
+
# @return [Calendar::Month, nil]
|
126
|
+
|
127
|
+
# @!method this_month
|
128
|
+
# Get the index-relative month for this month.
|
129
|
+
# Returns nil if no single month can be identified.
|
130
|
+
# @return [Calendar::Month, nil]
|
131
|
+
|
132
|
+
# @!method next_month
|
133
|
+
# Get the index-relative month 1 month forward.
|
134
|
+
# Returns nil if no single month can be identified.
|
135
|
+
# @return [Calendar::Month, nil]
|
136
|
+
|
137
|
+
### Quarters
|
138
|
+
|
139
|
+
# @!method in_quarter
|
140
|
+
# Get the index within the quarter that this unit falls in.
|
141
|
+
# Returns nil if no single quarter can be identified.
|
142
|
+
# @return [Integer, nil]
|
143
|
+
|
144
|
+
# @!method quarters_ago
|
145
|
+
# Get the index-relative quarter some number of quarters ago.
|
146
|
+
# Returns nil if no single quarter can be identified.
|
147
|
+
# @param offset [Integer] the number of quarters back to shift this period
|
148
|
+
# @return [Calendar::Quarter, nil]
|
149
|
+
|
150
|
+
# @!method quarters_ahead
|
151
|
+
# Get the index-relative quarter some number of quarters ahead.
|
152
|
+
# Returns nil if no single quarter can be identified.
|
153
|
+
# @param offset [Integer] the number of quarters forward to shift this period
|
154
|
+
# @return [Calendar::Quarter, nil]
|
155
|
+
|
156
|
+
# @!method last_quarter
|
157
|
+
# Get the index-relative quarter 1 quarter ago.
|
158
|
+
# Returns nil if no single quarter can be identified.
|
159
|
+
# @return [Calendar::Quarter, nil]
|
160
|
+
|
161
|
+
# @!method this_quarter
|
162
|
+
# Get the index-relative quarter for this quarter.
|
163
|
+
# Returns nil if no single quarter can be identified.
|
164
|
+
# @return [Calendar::Quarter, nil]
|
165
|
+
|
166
|
+
# @!method next_quarter
|
167
|
+
# Get the index-relative quarter 1 quarter forward.
|
168
|
+
# Returns nil if no single quarter can be identified.
|
169
|
+
# @return [Calendar::Quarter, nil]
|
170
|
+
|
171
|
+
### Halves
|
172
|
+
|
173
|
+
# @!method in_half
|
174
|
+
# Get the index within the half that this unit falls in.
|
175
|
+
# Returns nil if no single half can be identified.
|
176
|
+
# @return [Integer, nil]
|
177
|
+
|
178
|
+
# @!method halves_ago
|
179
|
+
# Get the index-relative half some number of halves ago.
|
180
|
+
# Returns nil if no single half can be identified.
|
181
|
+
# @param offset [Integer] the number of halves back to shift this period
|
182
|
+
# @return [Calendar::Half, nil]
|
183
|
+
|
184
|
+
# @!method halves_ahead
|
185
|
+
# Get the index-relative half some number of halves ahead.
|
186
|
+
# Returns nil if no single half can be identified.
|
187
|
+
# @param offset [Integer] the number of halves forward to shift this period
|
188
|
+
# @return [Calendar::Half, nil]
|
189
|
+
|
190
|
+
# @!method last_half
|
191
|
+
# Get the index-relative half 1 half ago.
|
192
|
+
# Returns nil if no single half can be identified.
|
193
|
+
# @return [Calendar::Half, nil]
|
194
|
+
|
195
|
+
# @!method this_half
|
196
|
+
# Get the index-relative half for this half.
|
197
|
+
# Returns nil if no single half can be identified.
|
198
|
+
# @return [Calendar::Half, nil]
|
199
|
+
|
200
|
+
# @!method next_half
|
201
|
+
# Get the index-relative half 1 half forward.
|
202
|
+
# Returns nil if no single half can be identified.
|
203
|
+
# @return [Calendar::Half, nil]
|
204
|
+
|
205
|
+
### Years
|
206
|
+
|
207
|
+
# @!method in_year
|
208
|
+
# Get the index within the year that this unit falls in.
|
209
|
+
# Returns nil if no single year can be identified.
|
210
|
+
# @return [Integer, nil]
|
211
|
+
|
212
|
+
# @!method years_ago
|
213
|
+
# Get the index-relative year some number of years ago.
|
214
|
+
# Returns nil if no single year can be identified.
|
215
|
+
# @param offset [Integer] the number of years back to shift this period
|
216
|
+
# @return [Calendar::Year, nil]
|
217
|
+
|
218
|
+
# @!method years_ahead
|
219
|
+
# Get the index-relative year some number of years ahead.
|
220
|
+
# Returns nil if no single year can be identified.
|
221
|
+
# @param offset [Integer] the number of years forward to shift this period
|
222
|
+
# @return [Calendar::Year, nil]
|
223
|
+
|
224
|
+
# @!method last_year
|
225
|
+
# Get the index-relative year 1 year ago.
|
226
|
+
# Returns nil if no single year can be identified.
|
227
|
+
# @return [Calendar::Year, nil]
|
228
|
+
|
229
|
+
# @!method this_year
|
230
|
+
# Get the index-relative year for this year.
|
231
|
+
# Returns nil if no single year can be identified.
|
232
|
+
# @return [Calendar::Year, nil]
|
233
|
+
|
234
|
+
# @!method next_year
|
235
|
+
# Get the index-relative year 1 year forward.
|
236
|
+
# Returns nil if no single year can be identified.
|
237
|
+
# @return [Calendar::Year, nil]
|
48
238
|
end
|
49
239
|
end
|
50
240
|
end
|