Class: Time

Inherits:
Object show all
Includes:
TimeFunctions
Defined in:
lib/sequel/fos_dates.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TimeFunctions

#as_minutes, #hm, #in_hundredths, #in_hundredths_rounded_xos, #in_tenths_rounded_xos, #to_fos_days

Class Method Details

.from_fos_time(minutes) ⇒ Object Also known as: from_minutes

using a date of 2000,1,1 is arbitrary



79
80
81
82
# File 'lib/sequel/fos_dates.rb', line 79

def self.from_fos_time(minutes)
  minutes = 0 unless minutes
  Time.utc(2000, 1, 1) + minutes.minutes
end

Instance Method Details

#long_viewObject

This is a view “February 01, 2010 01:40” that be parsed directly by javascript ie. in javascript you can say: Date.parse( “this to long view” ) and you will get a date object



102
103
104
# File 'lib/sequel/fos_dates.rb', line 102

def long_view
  self.strftime('%B %d, %Y %H:%M')
end

#original_to_sObject



71
# File 'lib/sequel/fos_dates.rb', line 71

alias :original_to_s :to_s

#to_datetimeObject

from Ruby Cookbook #########



89
90
91
92
93
94
95
96
97
# File 'lib/sequel/fos_dates.rb', line 89

def to_datetime
  # Convert seconds + microseconds into a fractional number of seconds
  seconds = sec + Rational(usec, 10**6)

  # Convert a UTC offset measured in minutes to one measured in a
  # fraction of a day.
  offset = Rational(utc_offset, 60 * 60 * 24)
  DateTime.new(year, month, day, hour, min, seconds, offset)
end

#to_s(args = nil) ⇒ Object



73
74
75
76
# File 'lib/sequel/fos_dates.rb', line 73

def to_s(args=nil)
  return self.strftime('%H:%M') if args == :hm or !args
  self.original_to_s(args)
end