Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/monkey-patch/time.rb

Instance Method Summary collapse

Instance Method Details

#start_of_centuryObject



98
99
100
# File 'lib/monkey-patch/time.rb', line 98

def start_of_century
  Time.parse strftime "#{year - year % 100}-01-01 00:00:00 %z"
end

#start_of_dayObject



69
70
71
# File 'lib/monkey-patch/time.rb', line 69

def start_of_day
  Time.parse strftime "%Y-%m-%d 00:00:00 %z"
end

#start_of_decadeObject



85
86
87
# File 'lib/monkey-patch/time.rb', line 85

def start_of_decade
  Time.parse strftime "#{year - year % 10}-01-01 00:00:00 %z"
end

#start_of_full_centuryObject



102
103
104
105
106
107
108
109
# File 'lib/monkey-patch/time.rb', line 102

def start_of_full_century
  century = if year % 100 == 0
              year - 99
            else
              year - year % 100 + 1
            end
  Time.parse strftime "#{century}-01-01 00:00:00 %z"
end

#start_of_full_decadeObject



89
90
91
92
93
94
95
96
# File 'lib/monkey-patch/time.rb', line 89

def start_of_full_decade
  decade = if year % 10 == 0
             year - 9
           else
             year - year % 10 + 1
           end
  Time.parse strftime "#{decade}-01-01 00:00:00 %z"
end

#start_of_half_dayObject



61
62
63
64
65
66
67
# File 'lib/monkey-patch/time.rb', line 61

def start_of_half_day
  if hour < 12
    Time.parse strftime "%Y-%m-%d 00:00:00 %z"
  else
    Time.parse strftime "%Y-%m-%d 12:00:00 %z"
  end
end

#start_of_half_hourObject



49
50
51
52
53
54
55
# File 'lib/monkey-patch/time.rb', line 49

def start_of_half_hour
  if min < 30
    Time.parse strftime "%Y-%m-%d %H:00:00 %z"
  else
    Time.parse strftime "%Y-%m-%d %H:30:00 %z"
  end
end

#start_of_hourObject



57
58
59
# File 'lib/monkey-patch/time.rb', line 57

def start_of_hour
  Time.parse strftime "%Y-%m-%d %H:00:00 %z"
end

#start_of_minuteObject



45
46
47
# File 'lib/monkey-patch/time.rb', line 45

def start_of_minute
  Time.parse strftime "%Y-%m-%d %H:%M:00 %z"
end

#start_of_monthObject



77
78
79
# File 'lib/monkey-patch/time.rb', line 77

def start_of_month
  Time.parse strftime "%Y-%m-01 00:00:00 %z"
end

#start_of_secondObject



41
42
43
# File 'lib/monkey-patch/time.rb', line 41

def start_of_second
  Time.parse strftime "%Y-%m-%d %H:%M:%S %z"
end

#start_of_weekObject



73
74
75
# File 'lib/monkey-patch/time.rb', line 73

def start_of_week
  start_of_day - wday.days
end

#start_of_yearObject



81
82
83
# File 'lib/monkey-patch/time.rb', line 81

def start_of_year
  Time.parse strftime "%Y-01-01 00:00:00 %z"
end