1 package AttrTimestampTestDummy;
3 use base qw(SL::DB::Object);
5 __PACKAGE__->meta->setup(
7 columns => [ dummy => { type => 'timestamp' }, ]
10 use SL::DB::Helper::Attr;
21 use Support::TestSetup;
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) }
26 Support::TestSetup::login();
28 $::myconfig{dateformat} = 'dd.mm.yy';
29 $::myconfig{numberformat} = '1.000,00';
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');
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');
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');
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');
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');
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');