|
1 |
package AttrTimestampTestDummy;
|
|
2 |
|
|
3 |
use base qw(SL::DB::Object);
|
|
4 |
|
|
5 |
__PACKAGE__->meta->setup(
|
|
6 |
table => 'dummy',
|
|
7 |
columns => [ dummy => { type => 'timestamp' }, ]
|
|
8 |
);
|
|
9 |
|
|
10 |
use SL::DB::Helper::Attr;
|
|
11 |
|
|
12 |
package main;
|
|
13 |
|
|
14 |
use strict;
|
|
15 |
|
|
16 |
use Test::More;
|
|
17 |
|
|
18 |
use lib 't';
|
|
19 |
use utf8;
|
|
20 |
|
|
21 |
use Support::TestSetup;
|
|
22 |
|
|
23 |
sub new { return AttrTimestampTestDummy->new(@_) }
|
|
24 |
sub new_dt { DateTime->new(year => 2014, month => 5, day => 31, hour => 23, minute => 9, second => 8, nanosecond => 12000000) }
|
|
25 |
|
|
26 |
Support::TestSetup::login();
|
|
27 |
|
|
28 |
$::myconfig{dateformat} = 'dd.mm.yy';
|
|
29 |
$::myconfig{numberformat} = '1.000,00';
|
|
30 |
|
|
31 |
is(new->dummy, undef, 'uninitialized: raw');
|
|
32 |
is(new->dummy_as_timestamp, undef, 'uninitialized: as_timestamp');
|
|
33 |
is(new->dummy_as_timestamp_s, undef, 'uninitialized: as_timestamp_s');
|
|
34 |
is(new->dummy_as_timestamp_ms, undef, 'uninitialized: as_timestamp_ms');
|
|
35 |
|
|
36 |
is(new(dummy => new_dt())->dummy, new_dt(), 'initialized with DateTime, raw');
|
|
37 |
is(new(dummy => new_dt())->dummy_as_timestamp, '31.05.2014 23:09', 'initialized with DateTime: as_timestamp');
|
|
38 |
is(new(dummy => new_dt())->dummy_as_timestamp_s, '31.05.2014 23:09:08', 'initialized with DateTime: as_timestamp_s');
|
|
39 |
is(new(dummy => new_dt())->dummy_as_timestamp_ms, '31.05.2014 23:09:08,012', 'initialized with DateTime: as_timestamp_ms');
|
|
40 |
|
|
41 |
is(new(dummy_as_timestamp => '31.05.2014')->dummy, new_dt()->truncate(to => 'day'), 'initialized with string: as_timestamp, precision day');
|
|
42 |
is(new(dummy_as_timestamp => '31.05.2014 23')->dummy, new_dt()->truncate(to => 'hour'), 'initialized with string: as_timestamp, precision hour');
|
|
43 |
is(new(dummy_as_timestamp => '31.05.2014 23:9')->dummy, new_dt()->truncate(to => 'minute'), 'initialized with string: as_timestamp, precision minute');
|
|
44 |
is(new(dummy_as_timestamp => '31.05.2014 23:9:8')->dummy, new_dt()->truncate(to => 'second'), 'initialized with string: as_timestamp, precision second');
|
|
45 |
is(new(dummy_as_timestamp => '31.05.2014 23:9:8,012')->dummy, new_dt(), 'initialized with string: as_timestamp, precision millisecond');
|
|
46 |
|
|
47 |
is(new(dummy_as_timestamp_s => '31.05.2014')->dummy, new_dt()->truncate(to => 'day'), 'initialized with string: as_timestamp_s, precision day');
|
|
48 |
is(new(dummy_as_timestamp_s => '31.05.2014 23')->dummy, new_dt()->truncate(to => 'hour'), 'initialized with string: as_timestamp_s, precision hour');
|
|
49 |
is(new(dummy_as_timestamp_s => '31.05.2014 23:9')->dummy, new_dt()->truncate(to => 'minute'), 'initialized with string: as_timestamp_s, precision minute');
|
|
50 |
is(new(dummy_as_timestamp_s => '31.05.2014 23:9:8')->dummy, new_dt()->truncate(to => 'second'), 'initialized with string: as_timestamp_s, precision second');
|
|
51 |
is(new(dummy_as_timestamp_s => '31.05.2014 23:9:8,012')->dummy, new_dt(), 'initialized with string: as_timestamp_s, precision millisecond');
|
|
52 |
|
|
53 |
is(new(dummy_as_timestamp_ms => '31.05.2014')->dummy, new_dt()->truncate(to => 'day'), 'initialized with string: as_timestamp_ms, precision day');
|
|
54 |
is(new(dummy_as_timestamp_ms => '31.05.2014 23')->dummy, new_dt()->truncate(to => 'hour'), 'initialized with string: as_timestamp_ms, precision hour');
|
|
55 |
is(new(dummy_as_timestamp_ms => '31.05.2014 23:9')->dummy, new_dt()->truncate(to => 'minute'), 'initialized with string: as_timestamp_ms, precision minute');
|
|
56 |
is(new(dummy_as_timestamp_ms => '31.05.2014 23:9:8')->dummy, new_dt()->truncate(to => 'second'), 'initialized with string: as_timestamp_ms, precision second');
|
|
57 |
is(new(dummy_as_timestamp_ms => '31.05.2014 23:9:8,012')->dummy, new_dt(), 'initialized with string: as_timestamp_ms, precision millisecond');
|
|
58 |
|
|
59 |
my $item = new();
|
|
60 |
is($item->dummy_as_timestamp_ms('31.05.2014'), '31.05.2014 00:00:00,000', 'return value of accessor as_timestamp_ms, precision day');
|
|
61 |
is($item->dummy_as_timestamp_ms('31.05.2014 23'), '31.05.2014 23:00:00,000', 'return value of accessor as_timestamp_ms, precision hour');
|
|
62 |
is($item->dummy_as_timestamp_ms('31.05.2014 23:9'), '31.05.2014 23:09:00,000', 'return value of accessor as_timestamp_ms, precision minute');
|
|
63 |
is($item->dummy_as_timestamp_ms('31.05.2014 23:9:8'), '31.05.2014 23:09:08,000', 'return value of accessor as_timestamp_ms, precision second');
|
|
64 |
is($item->dummy_as_timestamp_ms('31.05.2014 23:9:8,012'), '31.05.2014 23:09:08,012', 'return value of accessor as_timestamp_ms, precision millisecond');
|
|
65 |
|
|
66 |
done_testing();
|
Rose-Attr-Helfer: _as_timestamp
…mit verschiedenen Präzisionsstufen und Tests!