Class: DtTools
- Inherits:
-
Object
- Object
- DtTools
- Defined in:
- lib/gloo/objs/dt/dt_tools.rb
Class Method Summary collapse
-
.beginning_of_month(t) ⇒ Object
Returns the beginning of the month for the given time.
-
.beginning_of_week ⇒ Object
Get the beginning of the week.
-
.end_of_month(t) ⇒ Object
Returns the end of the month for the given time.
-
.get_utc_offset(t) ⇒ Object
——————————————————————— Begin/end Helpers ———————————————————————.
-
.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_month(t) ⇒ Object
Returns the beginning of the month for the given time.
114 115 116 117 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 114 def self.beginning_of_month t utc_offset = get_utc_offset t Time.new(t.year, t.month, 1, 0, 0, 0, utc_offset) end |
.beginning_of_week ⇒ Object
Get the beginning of the week.
31 32 33 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 31 def self.beginning_of_week return Time.now.beginning_of_week( start_day = :sunday ) end |
.end_of_month(t) ⇒ Object
Returns the end of the month for the given time.
122 123 124 125 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 122 def self.end_of_month t utc_offset = get_utc_offset t Time.new(t.year, t.month, t.end_of_month.day, 23, 59, 59, utc_offset) end |
.get_utc_offset(t) ⇒ Object
Begin/end Helpers
106 107 108 109 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 106 def self.get_utc_offset t utc_offset = ActiveSupport::TimeZone[ t.zone ].utc_offset return utc_offset end |
.in_next_ten_days?(dt) ⇒ Boolean
Is the date in the next 10 days?
38 39 40 41 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 38 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
18 19 20 21 22 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 18 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?
53 54 55 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 53 def self.is_future?( dt ) dt > Time.now.end_of_day end |
.is_past?(dt) ⇒ Boolean
Is the date in the past?
46 47 48 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 46 def self.is_past?( dt ) dt < Time.now.beginning_of_day end |
.is_this_week?(dt) ⇒ Boolean
Is the given date this week?
93 94 95 96 97 98 99 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 93 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?
60 61 62 63 64 65 66 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 60 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?
71 72 73 74 75 76 77 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 71 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?
82 83 84 85 86 87 88 |
# File 'lib/gloo/objs/dt/dt_tools.rb', line 82 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 |