swift 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/ext/result.cc +4 -4
- data/swift.gemspec +1 -1
- data/test/helper.rb +0 -2
- data/test/test_timestamps.rb +28 -26
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/ext/result.cc
CHANGED
@@ -88,10 +88,10 @@ static VALUE result_finish(VALUE self) {
|
|
88
88
|
}
|
89
89
|
|
90
90
|
// Calculates local offset at a given time, including dst.
|
91
|
-
|
91
|
+
int64_t client_tzoffset(int64_t local, int isdst) {
|
92
92
|
struct tm tm;
|
93
93
|
gmtime_r((const time_t*)&local, &tm);
|
94
|
-
return local + (isdst ? 3600 : 0) - mktime(&tm);
|
94
|
+
return (int64_t)(local + (isdst ? 3600 : 0) - mktime(&tm));
|
95
95
|
}
|
96
96
|
|
97
97
|
// pinched from do_postgres
|
@@ -108,7 +108,7 @@ static void reduce(uint64_t *numerator, uint64_t *denominator) {
|
|
108
108
|
|
109
109
|
VALUE typecast_datetime(const char *data, uint64_t len) {
|
110
110
|
struct tm tm;
|
111
|
-
|
111
|
+
int64_t epoch, adjust, offset;
|
112
112
|
|
113
113
|
double usec = 0;
|
114
114
|
char tzsign = 0;
|
@@ -148,7 +148,7 @@ VALUE typecast_datetime(const char *data, uint64_t len) {
|
|
148
148
|
reduce(&ajd_n, &ajd_d);
|
149
149
|
|
150
150
|
VALUE ajd = rb_rational_new(SIZET2NUM(ajd_n), SIZET2NUM(ajd_d));
|
151
|
-
return rb_funcall(cDateTime, fNewBang, 3, ajd, rb_rational_new(INT2FIX(
|
151
|
+
return rb_funcall(cDateTime, fNewBang, 3, ajd, rb_rational_new(INT2FIX(adjust), daysecs), sg);
|
152
152
|
}
|
153
153
|
|
154
154
|
// TODO: throw a warning ?
|
data/swift.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{swift}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Shane Hanna", "Bharanee 'Barney' Rathna"]
|
data/test/helper.rb
CHANGED
data/test/test_timestamps.rb
CHANGED
@@ -3,37 +3,39 @@ require 'date'
|
|
3
3
|
|
4
4
|
describe 'Adapter' do
|
5
5
|
supported_by Swift::DB::Postgres do
|
6
|
-
|
6
|
+
%w(Australia/Melboure America/Chicago).each do |timezone|
|
7
|
+
describe 'time parsing in %s' % timezone do
|
8
|
+
before do
|
9
|
+
@db = Swift.db
|
10
|
+
ENV['TZ'] = ":#{timezone}"
|
11
|
+
end
|
7
12
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
it 'should parse timestamps and do conversion accordingly' do
|
13
|
-
time = DateTime.parse('2010-01-01 15:00:00+04:30')
|
14
|
-
assert_timestamp_like time, fetch_timestamp_at(time), 'parses correctly'
|
15
|
-
end
|
13
|
+
it 'should parse timestamps and do conversion accordingly' do
|
14
|
+
time = DateTime.parse('2010-01-01 15:00:00+04:30')
|
15
|
+
assert_timestamp_like time, fetch_timestamp_at(time), 'parses correctly'
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
it 'should parse correctly when DST is on' do
|
19
|
+
time = DateTime.parse('2010-10-02 20:31:00+04:30')
|
20
|
+
assert_timestamp_like time, fetch_timestamp_at(time), 'DST on'
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
it 'should parse correctly when DST is off' do
|
24
|
+
time = DateTime.parse('2010-04-04 20:31:00+04:30')
|
25
|
+
assert_timestamp_like time, fetch_timestamp_at(time), 'DST off'
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
def fetch_timestamp_at value
|
29
|
+
sql = "select '%s'::timestamp with time zone as now" % value.strftime('%F %T%z')
|
30
|
+
@db.execute(sql)
|
31
|
+
@db.results.first.fetch(:now)
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
def assert_timestamp_like expect, given, comment
|
35
|
+
match = Regexp.new expect.to_time.strftime('%F %T')
|
36
|
+
assert_kind_of DateTime, given
|
37
|
+
assert_match match, given.strftime('%F %T'), comment
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|