class Date FOS_JD_OFFSET_DAYS = Date.parse('1899-12-31').jd DATE_FORMATS[:mdy] = "%m/%d/%Y" def self.from_fos_days(days) self.jd(FOS_JD_OFFSET_DAYS + days) end def to_fos_days jd - FOS_JD_OFFSET_DAYS end end module TimeFunctions def as_minutes hour*60 + min end def in_hundredths return 0 if hour + min == 0 minutes = hour*60 + min val = "#{minutes/60}.#{((100*(minutes.modulo(60)))/60).to_s.rjust(2, '0')}" BigDecimal.new(val, 2).round(1).to_s end # xos is rounding XOJET STYLE, which is a funky copy of how ipc did it def in_hundredths_rounded_xos return 0 if hour + min == 0 # It was determined that "ODD" increments of .05 (ie .15, .35, .55, .75, .95) of an hour (ie. 9,21,33,45,57 minutes) rounded UP whereas even increments of .05 rounded DOWN - sn minutes = as_minutes (minutes/60.0 + ([9, 21, 33, 45, 57].include?( min ) ? 0.001 : -0.001)).round(2) end # xos is rounding XOJET STYLE, which is a funky copy of how ipc did it def in_tenths_rounded_xos return 0 if hour + min == 0 # It was determined that "ODD" increments of .05 (ie .15, .35, .55, .75, .95) of an hour (ie. 9,21,33,45,57 minutes) rounded UP whereas even increments of .05 rounded DOWN - sn minutes = as_minutes (minutes/60.0 + ([9, 21, 33, 45, 57].include?( min ) ? 0.01 : -0.01)).round(1) end def hm to_s(:hm) end end class Time include TimeFunctions DATE_FORMATS[:hm] = "%H:%M" alias :original_to_s :to_s def to_s(args=nil) args = :hm unless args self.original_to_s(args) end # using a date of 2000,1,1 is arbitrary def self.from_fos_time(minutes) minutes = 0 unless minutes Time.utc(2000, 1, 1) + minutes.minutes end class << self alias from_minutes from_fos_time end end class DateTime include TimeFunctions # creates utc time from days and minutes def self.from_fos_date_time(days, minutes) days = 0 unless days minutes = 0 unless minutes Date.from_fos_days(days).to_datetime.advance(:minutes=>minutes) end def view to_s end # This is a view 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 def long_view to_s(:long) end end