Class: Code::Object::Time
Constant Summary
collapse
- DEFAULT_ZONE =
"Etc/UTC"
Constants inherited
from Code::Object
NUMBER_CLASSES
Instance Attribute Summary
#methods, #raw
Class Method Summary
collapse
Instance Method Summary
collapse
code_new, #code_new, maybe, #name, repeat, |
#<=>, #==, #as_json, #code_and, #code_as_json, #code_deep_duplicate, #code_different, #code_duplicate, #code_equal_equal, #code_equal_equal_equal, #code_exclamation_point, #code_exclusive_range, #code_falsy?, code_fetch, #code_fetch, #code_get, code_get, #code_inclusive_range, #code_inspect, #code_methods, #code_name, #code_or, #code_self, #code_set, code_set, #code_to_boolean, #code_to_class, #code_to_date, #code_to_decimal, #code_to_dictionary, #code_to_duration, #code_to_integer, #code_to_json, #code_to_list, #code_to_nothing, #code_to_parameter, #code_to_range, #code_to_string, #code_to_time, #code_truthy?, #eql?, #falsy?, #hash, #inspect, #multi_fetch, #nothing?, #sig, #succ, #to_code, #to_json, #to_s, #truthy?
Constructor Details
#initialize(*args, **_kargs, &_block) ⇒ Time
Returns a new instance of Time.
8
9
10
11
|
# File 'lib/code/object/time.rb', line 8
def initialize(*args, **_kargs, &_block)
::Time.zone ||= DEFAULT_ZONE
self.raw = ::Time.zone.parse(args.first.to_s) || ::Time.zone.now
end
|
Class Method Details
.call(**args) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/code/object/time.rb', line 13
def self.call(**args)
code_operator = args.fetch(:operator, nil).to_code
case code_operator.to_s
when "now"
sig(args)
code_now
when "tomorrow"
sig(args)
code_tomorrow
when "yesterday"
sig(args)
code_yesterday
when "year"
sig(args)
code_year
when "years"
sig(args)
code_years
when "month"
sig(args)
code_month
when "months"
sig(args)
code_months
when "week"
sig(args)
code_week
when "weeks"
sig(args)
code_weeks
when "week_day"
sig(args)
code_week_day
when "week_days"
sig(args)
code_week_days
when "day"
sig(args)
code_day
when "days"
sig(args)
code_days
when "hour"
sig(args)
code_hour
when "hours"
sig(args)
code_hours
when "minute"
sig(args)
code_minute
when "minutes"
sig(args)
code_minutes
when "second"
sig(args)
code_second
when "seconds"
sig(args)
code_seconds
when "monday?"
sig(args)
code_monday?
when "tuesday?"
sig(args)
code_tuesday?
when "wednesday?"
sig(args)
code_wednesday?
when "thursday?"
sig(args)
code_thursday?
when "friday?"
sig(args)
code_friday?
when "saturday?"
sig(args)
code_saturday?
when "sunday?"
sig(args)
code_sunday?
when "format"
sig(args) { String }
code_format(code_value)
else
super
end
end
|
150
151
152
|
# File 'lib/code/object/time.rb', line 150
def self.code_day
code_now.code_day
end
|
.code_days ⇒ Object
154
155
156
|
# File 'lib/code/object/time.rb', line 154
def self.code_days
code_now.code_days
end
|
210
211
212
|
# File 'lib/code/object/time.rb', line 210
def self.code_format(format)
code_now.code_format(format)
end
|
.code_friday? ⇒ Boolean
198
199
200
|
# File 'lib/code/object/time.rb', line 198
def self.code_friday?
code_week_day.code_five?
end
|
.code_hour ⇒ Object
158
159
160
|
# File 'lib/code/object/time.rb', line 158
def self.code_hour
code_now.code_hour
end
|
.code_hours ⇒ Object
162
163
164
|
# File 'lib/code/object/time.rb', line 162
def self.code_hours
code_now.code_hours
end
|
.code_minute ⇒ Object
166
167
168
|
# File 'lib/code/object/time.rb', line 166
def self.code_minute
code_now.code_minute
end
|
.code_minutes ⇒ Object
170
171
172
|
# File 'lib/code/object/time.rb', line 170
def self.code_minutes
code_now.code_minutes
end
|
.code_monday? ⇒ Boolean
182
183
184
|
# File 'lib/code/object/time.rb', line 182
def self.code_monday?
code_week_day.code_one?
end
|
.code_month ⇒ Object
126
127
128
|
# File 'lib/code/object/time.rb', line 126
def self.code_month
code_now.code_month
end
|
.code_months ⇒ Object
130
131
132
|
# File 'lib/code/object/time.rb', line 130
def self.code_months
code_now.code_months
end
|
113
114
115
116
|
# File 'lib/code/object/time.rb', line 113
def self.code_now
::Time.zone ||= DEFAULT_ZONE
new(::Time.zone.now)
end
|
.code_saturday? ⇒ Boolean
202
203
204
|
# File 'lib/code/object/time.rb', line 202
def self.code_saturday?
code_week_day.code_six?
end
|
.code_second ⇒ Object
174
175
176
|
# File 'lib/code/object/time.rb', line 174
def self.code_second
code_now.code_second
end
|
.code_seconds ⇒ Object
178
179
180
|
# File 'lib/code/object/time.rb', line 178
def self.code_seconds
code_now.code_seconds
end
|
.code_sunday? ⇒ Boolean
206
207
208
|
# File 'lib/code/object/time.rb', line 206
def self.code_sunday?
code_week_day.code_zero?
end
|
.code_thursday? ⇒ Boolean
194
195
196
|
# File 'lib/code/object/time.rb', line 194
def self.code_thursday?
code_week_day.code_four?
end
|
.code_tomorrow ⇒ Object
103
104
105
106
|
# File 'lib/code/object/time.rb', line 103
def self.code_tomorrow
::Time.zone ||= DEFAULT_ZONE
new(::Time.zone.tomorrow)
end
|
.code_tuesday? ⇒ Boolean
186
187
188
|
# File 'lib/code/object/time.rb', line 186
def self.code_tuesday?
code_week_day.code_two?
end
|
.code_wednesday? ⇒ Boolean
190
191
192
|
# File 'lib/code/object/time.rb', line 190
def self.code_wednesday?
code_week_day.code_three?
end
|
.code_week ⇒ Object
134
135
136
|
# File 'lib/code/object/time.rb', line 134
def self.code_week
code_now.code_week
end
|
.code_week_day ⇒ Object
142
143
144
|
# File 'lib/code/object/time.rb', line 142
def self.code_week_day
code_now.code_week_day
end
|
.code_week_days ⇒ Object
146
147
148
|
# File 'lib/code/object/time.rb', line 146
def self.code_week_days
code_now.code_week_days
end
|
.code_weeks ⇒ Object
138
139
140
|
# File 'lib/code/object/time.rb', line 138
def self.code_weeks
code_now.code_weeks
end
|
.code_year ⇒ Object
118
119
120
|
# File 'lib/code/object/time.rb', line 118
def self.code_year
code_now.code_year
end
|
.code_years ⇒ Object
122
123
124
|
# File 'lib/code/object/time.rb', line 122
def self.code_years
code_now.code_years
end
|
.code_yesterday ⇒ Object
108
109
110
111
|
# File 'lib/code/object/time.rb', line 108
def self.code_yesterday
::Time.zone ||= DEFAULT_ZONE
new(::Time.zone.yesterday)
end
|
Instance Method Details
#call(**args) ⇒ Object
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
# File 'lib/code/object/time.rb', line 214
def call(**args)
code_operator = args.fetch(:operator, nil).to_code
code_arguments = args.fetch(:arguments, []).to_code
code_value = code_arguments.code_first
case code_operator.to_s
when "after?"
sig(args) { Time.maybe }
code_after?(code_value)
when "before?"
sig(args) { Time.maybe }
code_before?(code_value)
when "past?"
sig(args)
code_past?
when "future?"
sig(args)
code_future?
when "year"
sig(args)
code_year
when "years"
sig(args)
code_years
when "month"
sig(args)
code_month
when "months"
sig(args)
code_months
when "week"
sig(args)
code_week
when "weeks"
sig(args)
code_weeks
when "week_day"
sig(args)
code_week_day
when "week_days"
sig(args)
code_week_days
when "day"
sig(args)
code_day
when "days"
sig(args)
code_days
when "hour"
sig(args)
code_hour
when "hours"
sig(args)
code_hours
when "minute"
sig(args)
code_minute
when "minutes"
sig(args)
code_minutes
when "second"
sig(args)
code_second
when "seconds"
sig(args)
code_seconds
when "monday?"
sig(args)
code_monday?
when "tuesday?"
sig(args)
code_tuesday?
when "wednesday?"
sig(args)
code_wednesday?
when "thursday?"
sig(args)
code_thursday?
when "friday?"
sig(args)
code_friday?
when "saturday?"
sig(args)
code_saturday?
when "sunday?"
sig(args)
code_sunday?
when "format"
sig(args) { String }
code_format(code_value)
else
super
end
end
|
#code_after?(other = nil) ⇒ Boolean
309
310
311
312
313
314
|
# File 'lib/code/object/time.rb', line 309
def code_after?(other = nil)
code_other = other.to_code
code_other = Time.code_now if code_other.nothing?
Boolean.new(raw.after?(code_other.raw))
end
|
#code_before?(other = nil) ⇒ Boolean
316
317
318
319
320
321
|
# File 'lib/code/object/time.rb', line 316
def code_before?(other = nil)
code_other = other.to_code
code_other = Time.code_now if code_other.nothing?
Boolean.new(raw.before?(code_other.raw))
end
|
363
364
365
|
# File 'lib/code/object/time.rb', line 363
def code_day
Integer.new(raw.day)
end
|
#code_days ⇒ Object
367
368
369
|
# File 'lib/code/object/time.rb', line 367
def code_days
Integer.new(raw.day)
end
|
423
424
425
426
427
|
# File 'lib/code/object/time.rb', line 423
def code_format(format)
code_format = format.to_code
String.new(raw.strftime(code_format.raw))
end
|
#code_friday? ⇒ Boolean
411
412
413
|
# File 'lib/code/object/time.rb', line 411
def code_friday?
code_week_day.code_five?
end
|
#code_future? ⇒ Boolean
327
328
329
|
# File 'lib/code/object/time.rb', line 327
def code_future?
code_after?
end
|
#code_hour ⇒ Object
371
372
373
|
# File 'lib/code/object/time.rb', line 371
def code_hour
Integer.new(raw.hour)
end
|
#code_hours ⇒ Object
375
376
377
|
# File 'lib/code/object/time.rb', line 375
def code_hours
Integer.new(raw.hour)
end
|
#code_minute ⇒ Object
379
380
381
|
# File 'lib/code/object/time.rb', line 379
def code_minute
Integer.new(raw.min)
end
|
#code_minutes ⇒ Object
383
384
385
|
# File 'lib/code/object/time.rb', line 383
def code_minutes
Integer.new(raw.min)
end
|
#code_monday? ⇒ Boolean
395
396
397
|
# File 'lib/code/object/time.rb', line 395
def code_monday?
code_week_day.code_one?
end
|
#code_month ⇒ Object
339
340
341
|
# File 'lib/code/object/time.rb', line 339
def code_month
Integer.new(raw.month)
end
|
#code_months ⇒ Object
343
344
345
|
# File 'lib/code/object/time.rb', line 343
def code_months
Integer.new(raw.month)
end
|
323
324
325
|
# File 'lib/code/object/time.rb', line 323
def code_past?
code_before?
end
|
#code_saturday? ⇒ Boolean
415
416
417
|
# File 'lib/code/object/time.rb', line 415
def code_saturday?
code_week_day.code_six?
end
|
#code_second ⇒ Object
387
388
389
|
# File 'lib/code/object/time.rb', line 387
def code_second
Integer.new(raw.sec)
end
|
#code_seconds ⇒ Object
391
392
393
|
# File 'lib/code/object/time.rb', line 391
def code_seconds
Integer.new(raw.sec)
end
|
#code_sunday? ⇒ Boolean
419
420
421
|
# File 'lib/code/object/time.rb', line 419
def code_sunday?
code_week_day.code_zero?
end
|
#code_thursday? ⇒ Boolean
407
408
409
|
# File 'lib/code/object/time.rb', line 407
def code_thursday?
code_week_day.code_four?
end
|
#code_tuesday? ⇒ Boolean
399
400
401
|
# File 'lib/code/object/time.rb', line 399
def code_tuesday?
code_week_day.code_two?
end
|
#code_wednesday? ⇒ Boolean
403
404
405
|
# File 'lib/code/object/time.rb', line 403
def code_wednesday?
code_week_day.code_three?
end
|
#code_week ⇒ Object
347
348
349
|
# File 'lib/code/object/time.rb', line 347
def code_week
Integer.new(raw.to_date.cweek)
end
|
#code_week_day ⇒ Object
355
356
357
|
# File 'lib/code/object/time.rb', line 355
def code_week_day
Integer.new(raw.wday)
end
|
#code_week_days ⇒ Object
359
360
361
|
# File 'lib/code/object/time.rb', line 359
def code_week_days
Integer.new(raw.wday)
end
|
#code_weeks ⇒ Object
351
352
353
|
# File 'lib/code/object/time.rb', line 351
def code_weeks
Integer.new(raw.to_date.cweek)
end
|
#code_year ⇒ Object
331
332
333
|
# File 'lib/code/object/time.rb', line 331
def code_year
Integer.new(raw.year)
end
|
#code_years ⇒ Object
335
336
337
|
# File 'lib/code/object/time.rb', line 335
def code_years
Integer.new(raw.year)
end
|