Class: DtTools

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo/objs/dt/dt_tools.rb

Overview

Author

Eric Crane (eric.crane@mac.com)

Copyright

Copyright © 2020 Eric Crane. All rights reserved.

A Date and Time object.

Class Method Summary collapse

Class Method Details

.beginning_of_weekObject

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?

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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