timeboss 0.0.10 → 0.1.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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.yardopts +1 -0
  4. data/README.md +1 -1
  5. data/doc/TimeBoss.html +146 -0
  6. data/doc/TimeBoss/Calendar.html +137 -0
  7. data/doc/TimeBoss/Calendar/Day.html +594 -0
  8. data/doc/TimeBoss/Calendar/Half.html +396 -0
  9. data/doc/TimeBoss/Calendar/Month.html +396 -0
  10. data/doc/TimeBoss/Calendar/Parser.html +386 -0
  11. data/doc/TimeBoss/Calendar/Period.html +841 -0
  12. data/doc/TimeBoss/Calendar/Quarter.html +396 -0
  13. data/doc/TimeBoss/Calendar/Support.html +131 -0
  14. data/doc/TimeBoss/Calendar/Support/Formatter.html +459 -0
  15. data/doc/TimeBoss/Calendar/Support/MonthBased.html +591 -0
  16. data/doc/TimeBoss/Calendar/Support/MonthBasis.html +437 -0
  17. data/doc/TimeBoss/Calendar/Support/MonthlyUnit.html +591 -0
  18. data/doc/TimeBoss/Calendar/Support/Navigable.html +723 -0
  19. data/doc/TimeBoss/Calendar/Support/Shiftable.html +138 -0
  20. data/doc/TimeBoss/Calendar/Support/Unit.html +1299 -0
  21. data/doc/TimeBoss/Calendar/Waypoints.html +155 -0
  22. data/doc/TimeBoss/Calendar/Waypoints/Absolute.html +1378 -0
  23. data/doc/TimeBoss/Calendar/Waypoints/Relative.html +4308 -0
  24. data/doc/TimeBoss/Calendar/Week.html +671 -0
  25. data/doc/TimeBoss/Calendar/Year.html +319 -0
  26. data/doc/TimeBoss/Calendars.html +336 -0
  27. data/doc/TimeBoss/Calendars/Broadcast.html +221 -0
  28. data/doc/TimeBoss/Calendars/Broadcast/Basis.html +278 -0
  29. data/doc/TimeBoss/Calendars/Entry.html +399 -0
  30. data/doc/TimeBoss/Support.html +115 -0
  31. data/doc/TimeBoss/Support/Shellable.html +249 -0
  32. data/doc/_index.html +416 -0
  33. data/doc/class_list.html +51 -0
  34. data/doc/css/common.css +1 -0
  35. data/doc/css/full_list.css +58 -0
  36. data/doc/css/style.css +496 -0
  37. data/doc/file.README.html +299 -0
  38. data/doc/file_list.html +56 -0
  39. data/doc/frames.html +17 -0
  40. data/doc/index.html +299 -0
  41. data/doc/js/app.js +314 -0
  42. data/doc/js/full_list.js +216 -0
  43. data/doc/js/jquery.js +4 -0
  44. data/doc/method_list.html +1139 -0
  45. data/doc/top-level-namespace.html +110 -0
  46. data/lib/timeboss.rb +4 -0
  47. data/lib/timeboss/calendar.rb +14 -0
  48. data/lib/timeboss/calendar/day.rb +10 -3
  49. data/lib/timeboss/calendar/half.rb +7 -2
  50. data/lib/timeboss/calendar/month.rb +7 -2
  51. data/lib/timeboss/calendar/parser.rb +1 -0
  52. data/lib/timeboss/calendar/period.rb +26 -11
  53. data/lib/timeboss/calendar/quarter.rb +7 -2
  54. data/lib/timeboss/calendar/support.rb +8 -0
  55. data/lib/timeboss/calendar/support/formatter.rb +1 -0
  56. data/lib/timeboss/calendar/support/month_basis.rb +3 -0
  57. data/lib/timeboss/calendar/support/{month_based.rb → monthly_unit.rb} +7 -1
  58. data/lib/timeboss/calendar/support/navigable.rb +25 -1
  59. data/lib/timeboss/calendar/support/shiftable.rb +3 -2
  60. data/lib/timeboss/calendar/support/unit.rb +24 -0
  61. data/lib/timeboss/calendar/waypoints.rb +6 -55
  62. data/lib/timeboss/calendar/waypoints/absolute.rb +114 -0
  63. data/lib/timeboss/calendar/waypoints/relative.rb +268 -0
  64. data/lib/timeboss/calendar/week.rb +11 -0
  65. data/lib/timeboss/calendar/year.rb +6 -5
  66. data/lib/timeboss/calendars.rb +16 -0
  67. data/lib/timeboss/version.rb +1 -1
  68. data/spec/calendar/support/{month_based_spec.rb → monthly_unit_spec.rb} +7 -7
  69. data/spec/calendars/broadcast_spec.rb +7 -7
  70. data/timeboss.gemspec +1 -0
  71. metadata +70 -7
@@ -6,6 +6,7 @@ require_relative './formatter'
6
6
  module TimeBoss
7
7
  class Calendar
8
8
  module Support
9
+ # A unit is the lowest-level base of all days/weeks/months, etc.
9
10
  class Unit
10
11
  include Navigable
11
12
  include Shiftable
@@ -21,22 +22,37 @@ module TimeBoss
21
22
  @end_date = end_date
22
23
  end
23
24
 
25
+ # Is the specified unit equal to this one, based on its unit type and date range?
26
+ # @param entry [Unit] the unit to compare
27
+ # @return [Boolean] true when periods are equal
24
28
  def ==(entry)
25
29
  self.class == entry.class && self.start_date == entry.start_date && self.end_date == entry.end_date
26
30
  end
27
31
 
32
+ # Format this period based on specified granularities.
33
+ # @param periods [Array<Symbol, String>] the periods to include (`half, week`, or `quarter`)
34
+ # @return [String] (e.g. "2020H2W7" or "2020Q3")
28
35
  def format(*periods)
29
36
  Formatter.new(self, periods.presence || Formatter::PERIODS).to_s
30
37
  end
31
38
 
39
+ # Starting from this unit of time, build a period extending through the specified time unit.
40
+ # @param unit [Unit] the period to extend through
41
+ # @return [Period]
32
42
  def thru(unit)
33
43
  Period.new(calendar, self, unit)
34
44
  end
35
45
 
46
+ # Does this period cover the current date?
47
+ # @return [Boolean]
36
48
  def current?
37
49
  Date.today.between?(start_date, end_date)
38
50
  end
39
51
 
52
+ # Return the unit relative to this one by the specified offset.
53
+ # Offset values can be positive or negative.
54
+ # @param value [Integer]
55
+ # @return [Unit]
40
56
  def offset(value)
41
57
  method = value.negative? ? :previous : :next
42
58
  base = self
@@ -44,14 +60,22 @@ module TimeBoss
44
60
  base
45
61
  end
46
62
 
63
+ # Move some number of units forward from this unit.
64
+ # @param value [Integer]
65
+ # @return [Unit]
47
66
  def +(value)
48
67
  offset(value)
49
68
  end
50
69
 
70
+ # Move some number of units backward from this unit.
71
+ # @param value [Integer]
72
+ # @return [Unit]
51
73
  def -(value)
52
74
  offset(-value)
53
75
  end
54
76
 
77
+ # Express this period as a date range.
78
+ # @return [Range<Date, Date>]
55
79
  def to_range
56
80
  @_to_range ||= start_date .. end_date
57
81
  end
@@ -1,62 +1,13 @@
1
1
  # frozen_string_literal: true
2
+
3
+ %w[absolute relative].each { |f| require_relative "./waypoints/#{f}" }
4
+
2
5
  module TimeBoss
3
6
  class Calendar
7
+ # Provides implementations for known periods within a calendar.
4
8
  module Waypoints
5
- %i[month quarter half year].each do |type|
6
- klass = TimeBoss::Calendar.const_get(type.to_s.classify)
7
- size = klass.const_get("NUM_MONTHS")
8
-
9
- define_method type do |year_index, index = 1|
10
- month = (index * size) - size + 1
11
- months = (month .. month + size - 1).map { |i| basis.new(year_index, i) }
12
- klass.new(self, year_index, index, months.first.start_date, months.last.end_date)
13
- end
14
-
15
- define_method "#{type}_for" do |date|
16
- window = send(type, date.year - 1, 1)
17
- while true
18
- break window if window.to_range.include?(date)
19
- window = window.next
20
- end
21
- end
22
- end
23
-
24
- def week(year_index, index)
25
- year(year_index).weeks[index - 1]
26
- end
27
-
28
- def week_for(date)
29
- year_for(date).weeks.find { |w| w.to_range.include?(date) }
30
- end
31
-
32
- def day(year_index, index)
33
- year(year_index).days[index - 1]
34
- end
35
-
36
- def day_for(date)
37
- Day.new(self, date)
38
- end
39
-
40
- %i[day week month quarter half year].each do |type|
41
- types = type.to_s.pluralize
42
-
43
- define_method("this_#{type}") { send("#{type}_for", Date.today) }
44
- define_method("last_#{type}") { send("this_#{type}").previous }
45
- define_method("next_#{type}") { send("this_#{type}").next }
46
-
47
- define_method("#{types}_for") { |p| send("#{type}_for", p.start_date).until(p.end_date) }
48
-
49
- define_method("#{types}_back") { |q| send("this_#{type}").previous(q) }
50
- define_method("#{types}_ago") { |q| send("this_#{type}").ago(q) }
51
-
52
- define_method("#{types}_forward") { |q| send("this_#{type}").next(q) }
53
- define_method("#{types}_hence") { |q| send("this_#{type}").hence(q) }
54
- alias_method types.to_sym, "#{types}_forward".to_sym
55
- end
56
-
57
- alias_method :yesterday, :last_day
58
- alias_method :today, :this_day
59
- alias_method :tomorrow, :next_day
9
+ include Absolute
10
+ include Relative
60
11
  end
61
12
  end
62
13
  end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+ module TimeBoss
3
+ class Calendar
4
+ module Waypoints
5
+ # Provides implementation for absolute periods within a calendar.
6
+ module Absolute
7
+ %i[month quarter half year].each do |type|
8
+ klass = TimeBoss::Calendar.const_get(type.to_s.classify)
9
+ size = klass.const_get("NUM_MONTHS")
10
+
11
+ define_method type do |year_index, index = 1|
12
+ month = (index * size) - size + 1
13
+ months = (month .. month + size - 1).map { |i| basis.new(year_index, i) }
14
+ klass.new(self, year_index, index, months.first.start_date, months.last.end_date)
15
+ end
16
+
17
+ define_method "#{type}_for" do |date|
18
+ window = send(type, date.year - 1, 1)
19
+ while true
20
+ break window if window.to_range.include?(date)
21
+ window = window.next
22
+ end
23
+ end
24
+ end
25
+
26
+ # Get the specified week by index within the specified year.
27
+ # @param year_index [Integer] the year to examine
28
+ # @param index [Integer] the index of the week within the year
29
+ # @return [Calendar::Week]
30
+ def week(year_index, index)
31
+ year(year_index).weeks[index - 1]
32
+ end
33
+
34
+ # Get the week that contains the specified date.
35
+ # @param date [Date] the date for which to locate the calendar week
36
+ # @return [Calendar::Week]
37
+ def week_for(date)
38
+ year_for(date).weeks.find { |w| w.to_range.include?(date) }
39
+ end
40
+
41
+ # Get the specified day by index within the specified year.
42
+ # @param year_index [Integer] the year to examine
43
+ # @param index [Integer] the index of the day within the year
44
+ # @return [Calendar::Day]
45
+ def day(year_index, index)
46
+ year(year_index).days[index - 1]
47
+ end
48
+
49
+ # Get the day that contains the specified date.
50
+ # @param date [Date] the date for which to locate the calendar day
51
+ # @return [Calendar::Day]
52
+ def day_for(date)
53
+ Day.new(self, date)
54
+ end
55
+
56
+ #
57
+ # i hate this
58
+ #
59
+
60
+ ### Month
61
+
62
+ # @!method month
63
+ # Get the specified month by index within the specified year
64
+ # @param year_index [Integer] the year to examine
65
+ # @param index [Integer] the index of the month within the year
66
+ # @return [Calendar::Month]
67
+
68
+ # @!method month_for
69
+ # Get the month that contains the specified date.
70
+ # @param date [Date] the date for which to locate the calendar month
71
+ # @return [Calendar::Month]
72
+
73
+ ### Quarter
74
+
75
+ # @!method quarter
76
+ # Get the specified quarter by index within the specified year
77
+ # @param year_index [Integer] the year to examine
78
+ # @param index [Integer] the index of the quarter within the year
79
+ # @return [Calendar::Quarter]
80
+
81
+ # @!method quarter_for
82
+ # Get the quarter that contains the specified date.
83
+ # @param date [Date] the date for which to locate the calendar quarter
84
+ # @return [Calendar::Quarter]
85
+
86
+ ### Half
87
+
88
+ # @!method half
89
+ # Get the specified half by index within the specified year
90
+ # @param year_index [Integer] the year to examine
91
+ # @param index [Integer] the index of the half within the year
92
+ # @return [Calendar::Half]
93
+
94
+ # @!method half_for
95
+ # Get the half that contains the specified date.
96
+ # @param date [Date] the date for which to locate the calendar half
97
+ # @return [Calendar::Half]
98
+
99
+ ### Year
100
+
101
+ # @!method year
102
+ # Get the specified year by index within the specified year
103
+ # @param year_index [Integer] the year to examine
104
+ # @param index [Integer] the index of the year within the year
105
+ # @return [Calendar::Year]
106
+
107
+ # @!method year_for
108
+ # Get the year that contains the specified date.
109
+ # @param date [Date] the date for which to locate the calendar year
110
+ # @return [Calendar::Year]
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,268 @@
1
+ # frozen_string_literal: true
2
+ module TimeBoss
3
+ class Calendar
4
+ module Waypoints
5
+ # Provides implementation for periods relative to today within a calendar.
6
+ module Relative
7
+ %i[day week month quarter half year].each do |type|
8
+ types = type.to_s.pluralize
9
+
10
+ define_method("this_#{type}") { send("#{type}_for", Date.today) }
11
+ define_method("last_#{type}") { send("this_#{type}").previous }
12
+ define_method("next_#{type}") { send("this_#{type}").next }
13
+
14
+ define_method("#{types}_for") { |p| send("#{type}_for", p.start_date).until(p.end_date) }
15
+
16
+ define_method("#{types}_back") { |q| send("this_#{type}").previous(q) }
17
+ define_method("#{types}_ago") { |q| send("this_#{type}").ago(q) }
18
+
19
+ define_method("#{types}_forward") { |q| send("this_#{type}").next(q) }
20
+ define_method("#{types}_ahead") { |q| send("this_#{type}").ahead(q) }
21
+ alias_method types.to_sym, "#{types}_forward".to_sym
22
+ end
23
+
24
+ alias_method :yesterday, :last_day
25
+ alias_method :today, :this_day
26
+ alias_method :tomorrow, :next_day
27
+
28
+ #
29
+ # i hate this
30
+ #
31
+
32
+ ### Days
33
+
34
+ # @!method this_day
35
+ # Get the current day within the active calendar.
36
+ # @return [Calendar::Day]
37
+
38
+ # @!method last_day
39
+ # Get the previous day within the active calendar.
40
+ # @return [Calendar::Day]
41
+
42
+ # @!method next_day
43
+ # Get the next day within the active calendar.
44
+ # @return [Calendar::Day]
45
+
46
+ # @!method days_for
47
+ # Get a list of days within the specified period unit.
48
+ # @param period [Calendar::Support::Unit] the containing period unit
49
+ # @return [Array<Calendar::Day>]
50
+
51
+ # @!method days_back
52
+ # Get a quantity of days back from today.
53
+ # @param quantity [Integer] the number of days requested
54
+ # @return [Array<Calendar::Day>]
55
+
56
+ # @!method days_ago
57
+ # Get the day that occurred the specified number of days ago.
58
+ # @param quantity [Integer] the number of days before today
59
+ # @return [Calendar::Day]
60
+
61
+ # @!method days_forward
62
+ # Get a quantity of days forward from today.
63
+ # @param quantity [Integer] the number of days requested
64
+ # @return [Array<Calendar::Day>]
65
+
66
+ # @!method days_ahead
67
+ # Get the day that occurred the specified number of days ahead.
68
+ # @param quantity [Integer] the number of days after today
69
+ # @return [Calendar::Day]
70
+
71
+ ### Weeks
72
+
73
+ # @!method this_week
74
+ # Get the current week within the active calendar.
75
+ # @return [Calendar::Week]
76
+
77
+ # @!method last_week
78
+ # Get the previous week within the active calendar.
79
+ # @return [Calendar::Week]
80
+
81
+ # @!method next_week
82
+ # Get the next week within the active calendar.
83
+ # @return [Calendar::Week]
84
+
85
+ # @!method weeks_for
86
+ # Get a list of weeks within the specified period unit.
87
+ # @param period [Calendar::Support::Unit] the containing period unit
88
+ # @return [Array<Calendar::Week>]
89
+
90
+ # @!method weeks_back
91
+ # Get a quantity of weeks back from this week.
92
+ # @param quantity [Integer] the number of weeks requested
93
+ # @return [Array<Calendar::Week>]
94
+
95
+ # @!method weeks_ago
96
+ # Get the week that occurred the specified number of weeks ago.
97
+ # @param quantity [Integer] the number of weeks before this week
98
+ # @return [Calendar::Week]
99
+
100
+ # @!method weeks_forward
101
+ # Get a quantity of weeks forward from this week.
102
+ # @param quantity [Integer] the number of weeks requested
103
+ # @return [Array<Calendar::Week>]
104
+
105
+ # @!method weeks_ahead
106
+ # Get the week that occurred the specified number of weeks ahead.
107
+ # @param quantity [Integer] the number of weeks after this week
108
+ # @return [Calendar::Week]
109
+
110
+ ### Months
111
+
112
+ # @!method this_month
113
+ # Get the current month within the active calendar.
114
+ # @return [Calendar::Month]
115
+
116
+ # @!method last_month
117
+ # Get the previous month within the active calendar.
118
+ # @return [Calendar::Month]
119
+
120
+ # @!method next_month
121
+ # Get the next month within the active calendar.
122
+ # @return [Calendar::Month]
123
+
124
+ # @!method months_for
125
+ # Get a list of months within the specified period unit.
126
+ # @param period [Calendar::Support::Unit] the containing period unit
127
+ # @return [Array<Calendar::Month>]
128
+
129
+ # @!method months_back
130
+ # Get a quantity of months back from this month.
131
+ # @param quantity [Integer] the number of months requested
132
+ # @return [Array<Calendar::Month>]
133
+
134
+ # @!method months_ago
135
+ # Get the month that occurred the specified number of months ago.
136
+ # @param quantity [Integer] the number of months before this month
137
+ # @return [Calendar::Month]
138
+
139
+ # @!method months_forward
140
+ # Get a quantity of months forward from this month.
141
+ # @param quantity [Integer] the number of months requested
142
+ # @return [Array<Calendar::Month>]
143
+
144
+ # @!method months_ahead
145
+ # Get the month that occurred the specified number of months ahead.
146
+ # @param quantity [Integer] the number of months after this month
147
+ # @return [Calendar::Month]
148
+
149
+ ### Quarters
150
+
151
+ # @!method this_quarter
152
+ # Get the current quarter within the active calendar.
153
+ # @return [Calendar::Quarter]
154
+
155
+ # @!method last_quarter
156
+ # Get the previous quarter within the active calendar.
157
+ # @return [Calendar::Quarter]
158
+
159
+ # @!method next_quarter
160
+ # Get the next quarter within the active calendar.
161
+ # @return [Calendar::Quarter]
162
+
163
+ # @!method quarters_for
164
+ # Get a list of quarters within the specified period unit.
165
+ # @param period [Calendar::Support::Unit] the containing period unit
166
+ # @return [Array<Calendar::Quarter>]
167
+
168
+ # @!method quarters_back
169
+ # Get a quantity of quarters back from this quarter.
170
+ # @param quantity [Integer] the number of quarters requested
171
+ # @return [Array<Calendar::Quarter>]
172
+
173
+ # @!method quarters_ago
174
+ # Get the quarter that occurred the specified number of quarters ago.
175
+ # @param quantity [Integer] the number of quarters before this quarter
176
+ # @return [Calendar::Quarter]
177
+
178
+ # @!method quarters_forward
179
+ # Get a quantity of quarters forward from this quarter.
180
+ # @param quantity [Integer] the number of quarters requested
181
+ # @return [Array<Calendar::Quarter>]
182
+
183
+ # @!method quarters_ahead
184
+ # Get the quarter that occurred the specified number of days ahead.
185
+ # @param quantity [Integer] the number of quarters after this quarter
186
+ # @return [Calendar::Quarter]
187
+
188
+ ### Halves
189
+
190
+ # @!method this_half
191
+ # Get the current half within the active calendar.
192
+ # @return [Calendar::Half]
193
+
194
+ # @!method last_half
195
+ # Get the previous half within the active calendar.
196
+ # @return [Calendar::Half]
197
+
198
+ # @!method next_half
199
+ # Get the next half within the active calendar.
200
+ # @return [Calendar::Half]
201
+
202
+ # @!method halves_for
203
+ # Get a list of halves within the specified period unit.
204
+ # @param period [Calendar::Support::Unit] the containing period unit
205
+ # @return [Array<Calendar::Half>]
206
+
207
+ # @!method halves_back
208
+ # Get a quantity of halves back from this half.
209
+ # @param quantity [Integer] the number of halves requested
210
+ # @return [Array<Calendar::Half>]
211
+
212
+ # @!method halves_ago
213
+ # Get the half that occurred the specified number of halves ago.
214
+ # @param quantity [Integer] the number of halves before this half
215
+ # @return [Calendar::Half]
216
+
217
+ # @!method halves_forward
218
+ # Get a quantity of halves forward from this half.
219
+ # @param quantity [Integer] the number of halves requested
220
+ # @return [Array<Calendar::Half>]
221
+
222
+ # @!method halves_ahead
223
+ # Get the half that occurred the specified number of halves ahead.
224
+ # @param quantity [Integer] the number of halves after this half
225
+ # @return [Calendar::Half]
226
+
227
+ ### Years
228
+
229
+ # @!method this_year
230
+ # Get the current year within the active calendar.
231
+ # @return [Calendar::Year]
232
+
233
+ # @!method last_year
234
+ # Get the previous year within the active calendar.
235
+ # @return [Calendar::Year]
236
+
237
+ # @!method next_year
238
+ # Get the next year within the active calendar.
239
+ # @return [Calendar::Year]
240
+
241
+ # @!method years_for
242
+ # Get a list of years within the specified period unit.
243
+ # @param period [Calendar::Support::Unit] the containing period unit
244
+ # @return [Array<Calendar::Year>]
245
+
246
+ # @!method years_back
247
+ # Get a quantity of years back from this year.
248
+ # @param quantity [Integer] the number of years requested
249
+ # @return [Array<Calendar::Year>]
250
+
251
+ # @!method years_ago
252
+ # Get the year that occurred the specified number of years ago.
253
+ # @param quantity [Integer] the number of years before this year
254
+ # @return [Calendar::Year]
255
+
256
+ # @!method years_forward
257
+ # Get a quantity of years forward from this year.
258
+ # @param quantity [Integer] the number of years requested
259
+ # @return [Array<Calendar::Year>]
260
+
261
+ # @!method years_ahead
262
+ # Get the year that occurred the specified number of years ahead.
263
+ # @param quantity [Integer] the number of years after this year
264
+ # @return [Calendar::Year]
265
+ end
266
+ end
267
+ end
268
+ end