Lines 142-147
eval {
Link Here
|
142 |
}; |
142 |
}; |
143 |
like( $@, qr/.*does not match the date format \(rfc3339\).*/, 'dt_from_string should die when passed a bad date string' ); |
143 |
like( $@, qr/.*does not match the date format \(rfc3339\).*/, 'dt_from_string should die when passed a bad date string' ); |
144 |
|
144 |
|
|
|
145 |
# ISO string tests |
146 |
subtest 'dt_from_string - iso format' => sub { |
147 |
plan tests => 6; |
148 |
|
149 |
# Dateonly |
150 |
my $dt_iso = dt_from_string( '2012-01-01', 'iso' ); |
151 |
cmp_ok( $dt_iso->epoch(), 'eq', '1325376000', 'dt_from_string handles dateonly string' ); |
152 |
|
153 |
eval { |
154 |
$dt_iso = dt_from_string( '2012-01-32', 'iso' ); |
155 |
}; |
156 |
like( $@, qr/^Validation failed/, 'Fail on invalid dateonly string'); |
157 |
|
158 |
# Datetime |
159 |
$dt_iso = dt_from_string( '2012-01-01T23:59:59', 'iso' ); |
160 |
cmp_ok( $dt_iso->epoch(), 'eq', '1325455199', 'dt_from_string with no offset assumes "local"' ); |
161 |
|
162 |
# Datetime with timezone |
163 |
$dt_iso = dt_from_string( '2012-01-01T23:59:59Z', 'iso' ); |
164 |
cmp_ok( $dt_iso->epoch(), 'eq', '1325455199', 'dt_from_string with UTC prescribed as Z' ); |
165 |
|
166 |
$dt_iso = dt_from_string( '2012-01-01T23:59:59+02:00', 'iso' ); |
167 |
cmp_ok( $dt_iso->epoch(), 'eq', '1325455199', 'dt_from_string with offset' ); |
168 |
|
169 |
$dt_iso = dt_from_string( '2012-01-01T23:59:59+02:00', 'iso' ); |
170 |
cmp_ok( $dt_iso->epoch(), 'eq', '1325455199', 'dt_from_string handles an offset' ); |
171 |
|
172 |
}; |
173 |
|
145 |
# Return undef if passed mysql 0 dates |
174 |
# Return undef if passed mysql 0 dates |
146 |
$dt0 = dt_from_string( '0000-00-00', 'iso' ); |
175 |
$dt0 = dt_from_string( '0000-00-00', 'iso' ); |
147 |
is( $dt0, undef, "undefined returned for 0 iso date" ); |
176 |
is( $dt0, undef, "undefined returned for 0 iso date" ); |
148 |
- |
|
|