Class: Time

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

Instance Method Summary collapse

Instance Method Details

#start_of_centuryObject



88
89
90
# File 'lib/monkey-patch/time.rb', line 88

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

#start_of_dayObject



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

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

#start_of_decadeObject



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

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

#start_of_half_dayObject



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

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



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

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



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

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

#start_of_minuteObject



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

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

#start_of_monthObject



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

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

#start_of_secondObject



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

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

#start_of_weekObject



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

def start_of_week
  start_of_day - wday.days
end

#start_of_yearObject



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

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