Class: DtTools
- Inherits:
-
Object
- Object
- DtTools
- Defined in:
- lib/gloo/objs/dt/dt_tools.rb
Overview
- Author
-
Eric Crane ([email protected])
- Copyright
-
Copyright © 2020 Eric Crane. All rights reserved.
A Date and Time object.
Class Method Summary collapse
-
.beginning_of_week ⇒ Object
Get the beginning of the week.
-
.in_next_ten_days?(dt) ⇒ Boolean
Is the date in the next 10 days?.
-
.is_dt_type?(obj) ⇒ Boolean
Is the given object a base Date Time object? True for DateTime and Time.
-
.is_future?(dt) ⇒ Boolean
Is the date in the future?.
-
.is_past?(dt) ⇒ Boolean
Is the date in the past?.
-
.is_this_week?(dt) ⇒ Boolean
Is the given date this week?.
-
.is_today?(dt) ⇒ Boolean
Is the given date today?.
-
.is_tomorrow?(dt) ⇒ Boolean
Is the given date tomorrow?.
-
.is_yesterday?(dt) ⇒ Boolean
Is the given date yesterday?.
Class Method Details
.beginning_of_week ⇒ Object
Get the beginning of the week.
30 31 32 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 30 def self.beginning_of_week return Time.now.beginning_of_week( start_day = :sunday ) end |
.in_next_ten_days?(dt) ⇒ Boolean
Is the date in the next 10 days?
37 38 39 40 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 37 def self.in_next_ten_days?( dt ) return false if DtTools.is_past?( dt ) dt < 10.days.from_now.end_of_day end |
.is_dt_type?(obj) ⇒ Boolean
Is the given object a base Date Time object? True for DateTime and Time
17 18 19 20 21 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 17 def self.is_dt_type? obj return true if obj.is_a? ::DateTime return true if obj.is_a? ::Time return false end |
.is_future?(dt) ⇒ Boolean
Is the date in the future?
52 53 54 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 52 def self.is_future?( dt ) dt > Time.now.end_of_day end |
.is_past?(dt) ⇒ Boolean
Is the date in the past?
45 46 47 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 45 def self.is_past?( dt ) dt < Time.now.beginning_of_day end |
.is_this_week?(dt) ⇒ Boolean
Is the given date this week?
92 93 94 95 96 97 98 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 92 def self.is_this_week?( dt ) return false if dt.blank? dt = Chronic.parse( dt ) if dt.is_a?( String ) return false if dt <= ::Time.now.beginning_of_week( start_day = :sunday ) return false if dt >= ::Time.now.end_of_week( start_day = :sunday ) return true end |
.is_today?(dt) ⇒ Boolean
Is the given date today?
59 60 61 62 63 64 65 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 59 def self.is_today?( dt ) return false if dt.blank? dt = Chronic.parse( dt ) if dt.is_a? String return false if dt <= ::Time.now.beginning_of_day return false if dt >= ::Time.now.end_of_day return true end |
.is_tomorrow?(dt) ⇒ Boolean
Is the given date tomorrow?
70 71 72 73 74 75 76 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 70 def self.is_tomorrow?( dt ) return false if dt.blank? dt = Chronic.parse( dt ) if dt.is_a? String return false if dt <= ( ::Time.now.beginning_of_day + 1.day ) return false if dt >= ( ::Time.now.end_of_day + 1.day ) return true end |
.is_yesterday?(dt) ⇒ Boolean
Is the given date yesterday?
81 82 83 84 85 86 87 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 81 def self.is_yesterday?( dt ) return false if dt.blank? dt = Chronic.parse( dt ) if dt.is_a? String return false if dt <= ( ::Time.now.beginning_of_day - 1.day ) return false if dt >= ( ::Time.now.end_of_day - 1.day ) return true end |