Module: Cubicle::DateTime
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.db_time_format ⇒ Object
3 4 5 |
# File 'lib/cubicle/date_time.rb', line 3 def self.db_time_format @time_format ||= :iso8601 #or :native || :time || anything not :iso8601 end |
.db_time_format=(time_format) ⇒ Object
7 8 9 10 |
# File 'lib/cubicle/date_time.rb', line 7 def self.db_time_format=(time_format) raise "db_time_format must be :iso8601 or :native" unless [:iso8601,:native].include?(time_format) @time_format=time_format end |
.iso8601? ⇒ Boolean
12 13 14 |
# File 'lib/cubicle/date_time.rb', line 12 def self.iso8601? self.db_time_format == :iso8601 end |
Instance Method Details
#beginning_of(period) ⇒ Object
29 30 31 |
# File 'lib/cubicle/date_time.rb', line 29 def beginning_of(period) self.send "beginning_of_#{period.to_s.singularize}" end |
#iso8601? ⇒ Boolean
16 17 18 |
# File 'lib/cubicle/date_time.rb', line 16 def iso8601? Cubicle::DateTime.iso8601? end |
#to_cubicle(period = :date) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/cubicle/date_time.rb', line 20 def to_cubicle(period = :date) case period when :year, :years then iso8601? ? self.strftime('%Y') : beginning_of_year when :quarter, :quarters then iso8601? ? "#{db_year}-Q#{(month+2) / 3}" : beginning_of_quarter when :month, :months then iso8601? ? self.strftime('%Y-%m') : beginning_of_month else iso8601? ? self.strftime('%Y-%m-%d') : self end end |