Module: Lazier::DateTime
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/lazier/datetime.rb
Overview
Extensions for date and time objects.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary (collapse)
-
- (Fixnum) in_months(base = nil)
Returns the number of months passed between the beginning of the base year and the current date.
-
- (String) local_lstrftime(format = nil)
Formats a datetime in the current timezone, looking up also custom formats.
-
- (String) local_strftime(format = nil)
Formats a datetime in the current timezone.
-
- (String) lstrftime(format = nil)
Formats a datetime, looking up also custom formats.
-
- (String) padded_month
Returns the current month number with leading 0.
-
- (UTC::Time) utc_time
Returns the UTC::Time representation of the current datetime.
Instance Method Details
- (Fixnum) in_months(base = nil)
Returns the number of months passed between the beginning of the base year and the current date.
ruby
DateTime.civil(2013, 6, 1).in_months(2011)
# => 18
227 228 229 |
# File 'lib/lazier/datetime.rb', line 227 def in_months(base = nil) (year - (base || ::Date.today.year)) * 12 + month end |
- (String) local_lstrftime(format = nil)
Formats a datetime in the current timezone, looking up also custom formats.
260 261 262 |
# File 'lib/lazier/datetime.rb', line 260 def local_lstrftime(format = nil) (respond_to?(:in_time_zone) ? in_time_zone : self).lstrftime(format) end |
- (String) local_strftime(format = nil)
Formats a datetime in the current timezone.
251 252 253 |
# File 'lib/lazier/datetime.rb', line 251 def local_strftime(format = nil) (respond_to?(:in_time_zone) ? in_time_zone : self).strftime(::DateTime.custom_format(format)) end |
- (String) lstrftime(format = nil)
Formats a datetime, looking up also custom formats.
243 244 245 |
# File 'lib/lazier/datetime.rb', line 243 def lstrftime(format = nil) strftime(::DateTime.custom_format(format.to_s).gsub(/(?<!%)(%[ab])/i) { |mo| localize_time_component(mo) }) end |
- (String) padded_month
Returns the current month number with leading 0.
234 235 236 |
# File 'lib/lazier/datetime.rb', line 234 def padded_month month.indexize end |
- (UTC::Time) utc_time
Returns the UTC::Time representation of the current datetime.
214 215 216 |
# File 'lib/lazier/datetime.rb', line 214 def utc_time utc.to_time end |