fossil 0.3.27 → 0.3.28
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/fossil.gemspec +1 -1
- data/lib/models/trip_leg.rb +1 -1
- data/lib/sequel/fos_dates.rb +40 -50
- data/lib/sequel/model_patch.rb +5 -3
- data/spec/sequel/fos_dates_spec.rb +2 -3
- data/spec/sequel/model_patch_spec.rb +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.28
|
data/fossil.gemspec
CHANGED
data/lib/models/trip_leg.rb
CHANGED
@@ -711,7 +711,7 @@ class TripLeg < Sequel::Model(:'trip legs')
|
|
711
711
|
|
712
712
|
def ebt_time
|
713
713
|
minutes_between = (planned_arrival_date_time_gmt - planned_departure_date_time_gmt)/60;
|
714
|
-
Time.
|
714
|
+
Time.from_minutes(minutes_between)
|
715
715
|
end
|
716
716
|
|
717
717
|
#### aliases and special methods #####
|
data/lib/sequel/fos_dates.rb
CHANGED
@@ -13,59 +13,42 @@ end
|
|
13
13
|
|
14
14
|
module TimeFunctions
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
klass.send(:extend,TimeFunctions::ClassMethods)
|
16
|
+
def as_minutes
|
17
|
+
hour*60 + min
|
19
18
|
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
def in_hundredths
|
27
|
-
return 0 if hour + min == 0
|
28
|
-
minutes = hour*60 + min
|
29
|
-
val = "#{minutes/60}.#{((100*(minutes.modulo(60)))/60).to_s.rjust(2, '0')}"
|
30
|
-
BigDecimal.new(val, 2).round(1).to_s
|
31
|
-
end
|
32
|
-
|
33
|
-
# xos is rounding XOJET STYLE, which is a funky copy of how ipc did it
|
34
|
-
def in_hundredths_rounded_xos
|
35
|
-
return 0 if hour + min == 0
|
36
|
-
# 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
|
37
|
-
minutes = as_minutes
|
38
|
-
(minutes/60.0 + ([9, 21, 33, 45, 57].include?( min ) ? 0.001 : -0.001)).round(2)
|
39
|
-
end
|
40
|
-
|
41
|
-
# xos is rounding XOJET STYLE, which is a funky copy of how ipc did it
|
42
|
-
def in_tenths_rounded_xos
|
43
|
-
return 0 if hour + min == 0
|
44
|
-
# 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
|
45
|
-
minutes = as_minutes
|
46
|
-
(minutes/60.0 + ([9, 21, 33, 45, 57].include?( min ) ? 0.01 : -0.01)).round(1)
|
47
|
-
end
|
48
|
-
|
49
|
-
def hm
|
50
|
-
to_s(:hm)
|
51
|
-
end
|
20
|
+
def in_hundredths
|
21
|
+
return 0 if hour + min == 0
|
22
|
+
minutes = hour*60 + min
|
23
|
+
val = "#{minutes/60}.#{((100*(minutes.modulo(60)))/60).to_s.rjust(2, '0')}"
|
24
|
+
BigDecimal.new(val, 2).round(1).to_s
|
52
25
|
end
|
53
26
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
27
|
+
# xos is rounding XOJET STYLE, which is a funky copy of how ipc did it
|
28
|
+
def in_hundredths_rounded_xos
|
29
|
+
return 0 if hour + min == 0
|
30
|
+
# 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
|
31
|
+
minutes = as_minutes
|
32
|
+
(minutes/60.0 + ([9, 21, 33, 45, 57].include?( min ) ? 0.001 : -0.001)).round(2)
|
33
|
+
end
|
34
|
+
|
35
|
+
# xos is rounding XOJET STYLE, which is a funky copy of how ipc did it
|
36
|
+
def in_tenths_rounded_xos
|
37
|
+
return 0 if hour + min == 0
|
38
|
+
# 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
|
39
|
+
minutes = as_minutes
|
40
|
+
(minutes/60.0 + ([9, 21, 33, 45, 57].include?( min ) ? 0.01 : -0.01)).round(1)
|
41
|
+
end
|
59
42
|
|
60
|
-
|
61
|
-
|
62
|
-
DateTime.new(1899, 12, 31).advance(:minutes=>minutes)
|
63
|
-
end
|
43
|
+
def hm
|
44
|
+
to_s(:hm)
|
64
45
|
end
|
46
|
+
|
65
47
|
end
|
66
48
|
|
67
49
|
class Time
|
68
50
|
include TimeFunctions
|
51
|
+
|
69
52
|
DATE_FORMATS[:hm] = "%H:%M"
|
70
53
|
|
71
54
|
alias :original_to_s :to_s
|
@@ -75,17 +58,24 @@ class Time
|
|
75
58
|
self.original_to_s(args)
|
76
59
|
end
|
77
60
|
|
78
|
-
#
|
79
|
-
# to ensure that if you want to convert the DateTime that this function returns,
|
80
|
-
# you can convert is safely to a Time class. To do this the Date part must be
|
81
|
-
# at least (1901,12,14), so I am rounding to (1902,1,1), and calling that
|
82
|
-
# the beginning date for a time with no hours, mins and seconds.
|
61
|
+
# using a date of 2000,1,1 is arbitrary
|
83
62
|
def self.from_fos_time(minutes)
|
84
|
-
|
85
|
-
|
63
|
+
minutes = 0 unless minutes
|
64
|
+
Time.utc(2000, 1, 1) + minutes.minutes
|
65
|
+
end
|
66
|
+
|
67
|
+
class << self
|
68
|
+
alias from_minutes from_fos_time
|
86
69
|
end
|
87
70
|
end
|
88
71
|
|
89
72
|
class DateTime
|
90
73
|
include TimeFunctions
|
74
|
+
|
75
|
+
# creates utc time from days and minutes
|
76
|
+
def self.from_fos_date_time(days, minutes)
|
77
|
+
days = 0 unless days
|
78
|
+
minutes = 0 unless minutes
|
79
|
+
Date.from_fos_days(days).to_datetime.advance(:minutes=>minutes)
|
80
|
+
end
|
91
81
|
end
|
data/lib/sequel/model_patch.rb
CHANGED
@@ -103,7 +103,7 @@ class Sequel::Model
|
|
103
103
|
inst_def datetime_column_name do
|
104
104
|
days = send(:[], date_column) || 0 # nil defaults to 0 days
|
105
105
|
minutes = send(:[], time_column) || 0 # nil defaults to 0 minutes
|
106
|
-
|
106
|
+
DateTime.from_fos_date_time(days, minutes) # returns utc time
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
@@ -189,9 +189,11 @@ class Sequel::Model
|
|
189
189
|
column_value = send(column_name)
|
190
190
|
case type
|
191
191
|
when :date
|
192
|
-
Date.from_fos_days(column_value)
|
192
|
+
Date.from_fos_days(column_value)
|
193
|
+
# Date.from_fos_days(column_value) if column_value
|
193
194
|
when :time
|
194
|
-
Time.
|
195
|
+
Time.from_fos_time(column_value)
|
196
|
+
# Time.utc(2000,1,1) + column_value.minutes if column_value
|
195
197
|
when :currency
|
196
198
|
number_to_currency( (column_value || 0).to_f/100, :unit=>'', :precision=>2)
|
197
199
|
when :precision
|
@@ -4,7 +4,6 @@ describe "fos_dates" do
|
|
4
4
|
|
5
5
|
it "Time and DateTime have proper class methods included from TimeFunctions" do
|
6
6
|
Time.should respond_to(:from_fos_time)
|
7
|
-
DateTime.should respond_to(:from_fos_time)
|
8
7
|
end
|
9
8
|
|
10
9
|
it "Time and DateTime have proper class methods included from TimeFunctions" do
|
@@ -17,11 +16,11 @@ describe "fos_dates" do
|
|
17
16
|
end
|
18
17
|
|
19
18
|
it "converts fos time number of 0 to a DateTime of (1902,1,1)" do
|
20
|
-
Time.from_fos_time(0).should == DateTime.new(
|
19
|
+
Time.from_fos_time(0).should == DateTime.new(2000,1,1,0,0,0).to_time
|
21
20
|
end
|
22
21
|
|
23
22
|
it "converts fos time number to a Ruby DateTime" do
|
24
|
-
Time.from_fos_time(100).should == DateTime.new(
|
23
|
+
Time.from_fos_time(100).should == DateTime.new(2000,1,1,1,40,0).to_time
|
25
24
|
end
|
26
25
|
|
27
26
|
it "converts a Ruby Time to hundredths" do
|
@@ -265,7 +265,7 @@ describe "Sequel::Model extentions" do
|
|
265
265
|
|
266
266
|
it "datetime can handle nil date or time" do
|
267
267
|
add_test_table_data({:date_col => nil, :time_col => nil})
|
268
|
-
TestTable.first.datetime_col.should == DateTime.new(
|
268
|
+
TestTable.first.datetime_col.should == DateTime.new(1899,12,31,0,0,0)
|
269
269
|
end
|
270
270
|
|
271
271
|
end
|