# Copyright (c) 2005-2010 bivio Software, Inc. All rights reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: DateTime.bunit,v 1.28 2011/11/05 23:51:26 nagler Exp $ Type(); req()->put(timezone => 120); req()->initialize_fully; my($counter) = 0; [ class() => [ is_date => [ '2396759 79199' => 1, '2396759 79198' => 0, ], is_time => [ '2378497 7200' => 1, '2396759 7200' => 0, '2396759 79199' => 0, ], from_date_and_time => [ ['2396759 79199', '2378497 7200'] => '2396759 7200', ['2396759 7200', '2378497 7200'] => DIE(), ['2396759 79199', '2396759 7200'] => DIE(), ], set_local_end_of_day => [ '2453647 7200' => '2453648 7199', '2453647 7199' => '2453647 7199', ['2453647 86399', 0] => '2453647 86399', ['2453647 0', 0] => '2453647 86399', ['2453647 82800', -60] => ['2453648 82799'], ['2453647 82799', -60] => ['2453647 82799'], ['2453647 79199', -60] => '2453647 82799', #BUG: The routine takes a DateTime, but we want to treat Date specially # so we check the time part. No way to know if this is a date or a datetime # whose time part is 21:59:59 ['2453647 79199', -180] => '2453647 75599', ], set_local_beginning_of_day => [ '2453647 7199' => '2453646 7200', '2453647 7200' => '2453647 7200', ['2453647 00000', 0] => ['2453647 0'], ['2453647 82799', -60] => ['2453646 82800'], ['2453647 82800', -60] => ['2453647 82800'], ], set_local_time_part => [ ['2453647 7199', 100] => '2453646 7300', ['2453647 7200', 100] => '2453647 7300', ['2453647 7299', 100] => '2453647 7300', ['2453647 7300', 100] => '2453647 7300', ['2453647 7301', 100] => '2453647 7300', ], from_literal => [ [undef] => [undef], '2378497 9' => '2378497 9', '-9' => DATE_TIME(), 'Feb 29 0:0:0 MST 1972' => '2441377 0', 'Feb 29 13:13:13 XXX 2000' => '2451604 47593', '1972/2/29 0:0:0' => '2441377 0', '2000/2/29 13:13:13' => '2451604 47593', 'Sun Dec 16 13:47:35 GMT 2001' => '2452260 49655', '20000229131313' => '2451604 47593', 'Wed, 26 Oct 2005 04:19:47 GMT' => '2453670 15587', 'Wed, 26 Oct 2005 04:19:47 EDT' => '2453670 29987', '20000229T131313Z' => '2451604 47593', '20000229T131313' => '2451604 54793', '2000/02/29 13:13:13' => '2451604 47593', '2000-02-29 13:13' => '2451604 47580', '[05/Nov/2011:14:09:46 -0600]' => '2455871 72586', '05/Nov/2011:14:09:46 -0600' => '2455871 72586', ], from_local_literal => [ [undef] => [undef, undef], '2378497 9' => '2378497 7209', '-9' => DATE_TIME(), 'Feb 29 0:0:0 MST 1972' => '2441377 7200', 'Feb 29 13:13:13 GMT 2000' => '2451604 54793', '1972/2/29 0:0:0' => '2441377 7200', '2000/2/29 13:13:13' => '2451604 54793', ], to_string => [ '2378497 9' => '01/01/1800 00:00:09 GMT', '2441377 0' => '02/29/1972 00:00:00 GMT', '2451604 47593' => '02/29/2000 13:13:13 GMT', ], to_local_string => [ '2378497 7209' => '01/01/1800 00:00:09', '2441377 7200' => '02/29/1972 00:00:00', '2451604 54793' => '02/29/2000 13:13:13', ], to_local_file_name => [ '2441377 7200' => '19720229000000', ['2441377 7200', -60] => '19720229030000', ], to_parts => [ class()->get_min => ['0', '0', '0', '1', '1', '1800'], class()->get_max => ['59', '59', '23', '31', '12', '2199'], '2440588 0' => ['0', '0', '0', '1', '1', '1970'], '2441377 0' => ['0', '0', '0', '29', '2', '1972'], '2451604 47593' => ['13', '13', '13', '29', '2', '2000'], '1160085500' => ['20', '58', '15', '5', '10', '2006'], ], to_time_parts => [ '2451604 47593' => [qw(13 13 13)], ], to_file_name => [ '2451604 47593' => '20000229131313', ], to_date_parts => [ '2451604 47593' => [qw(29 2 2000)], ], to_alert => [ '2441377 7200' => '1972/02/29 02:00:00', ], add_days => [ ['2440588 0', 1] => '2440589 0', ['2440588 0', -1] => '2440587 0', ], add_seconds => [ ['2440588 0', 1] => '2440588 1', ['2440588 0', 86401] => '2440589 1', ['2440588 0', -86401] => '2440586 86399', ['2440588 0', -1] => '2440587 86399', ], add_months => [ [DateTime('1/1/2012 1:2:3'), 1] => DateTime('2/1/2012 1:2:3'), [DateTime('1/1/2012 1:2:3'), -1] => DateTime('12/1/2011 1:2:3'), [DateTime('3/29/2012 1:2:3'), -1] => DateTime('2/29/2012 1:2:3'), [DateTime('3/30/2012 1:2:3'), -1] => DateTime('2/29/2012 1:2:3'), [DateTime('1/31/2010 1:2:3'), 1] => DateTime('2/28/2010 1:2:3'), ], add_years => [ [DateTime('2/29/2012 1:2:3'), 1] => DateTime('2/28/2013 1:2:3'), [DateTime('2/29/2012 1:2:3'), -1] => DateTime('2/28/2011 1:2:3'), ], from_parts_or_die => [ ['13', '13', '13', '29', '2', '2000'] => '2451604 47593', ['13', '13', '29', '2', '2000'] => DIE(), ], date_from_parts_or_die => [ ['29', '2', '2000'] => '2451604 79199', ['32', '2', '2000'] => DIE(), ], delta_days => [ ['2452874 05700', '2452874 05700'] => 0, ['2452874 05700', '2452874 27300'] => 0.25, ['2452874 05700', '2452873 48900'] => -0.5, ['2452874 05700', '2452888 06240'] => 14.00625, ['2452874 05700', '2452868 03540'] => -6.025, ], # Just make sure it doesn't blow gettimeofday => sub { my($case, $actual) = @_; my($s, $us) = @{$actual->[0]}; die($us, ': microseconds greater than 1m') unless $us < 1_000_000; return $s <= time ? 1 : 0; }, compare => [ ['2452874 05700', '2452874 05700'] => 0, ['2452874 05700', '2452874 27300'] => -1, ['2452874 05700', '2452873 48900'] => 1, [undef, '2452873 48900'] => -1, ['2452873 48900', undef] => 1, [undef, undef] => 0, ], is_equal => [ ['2452874 05700', '2452874 05700'] => 1, ['2452874 05700', '2452874 27300'] => 0, ['2452874 05700', '2452873 48900'] => 0, [undef, '2452873 48900'] => 0, ['2452873 48900', undef] => 0, [undef, undef] => 1, ], is_valid_specified => [ '0 0' => 0, '' => 0, '2452874 05700' => 1, ], english_month3 => [ 1 => 'Jan', 12 => 'Dec', ], english_month3_to_int => [ Feb => 2, Mar => 3, ], get_parts => [ ['2378497 9', 'year'] => 1800, ['2378497 9', 'YEAR'] => 1800, ['2378497 9', 'YEAR', 'MONTH'] => [1800, 1], ['2378497 9', 'UNKNOWN_PART'] => DIE(), ], { method => 'get_parts', want_scalar => 1, } => [ ['2378497 9', 'year'] => 1800, ['2378497 9', 'year', 'month'] => DIE(), ], { method => 'handle_pre_execute_task', compute_params => sub { my($case, $params) = @_; req()->put(query => {date_time_test_now => $params->[0]}); return [req('task'), req()]; }, } => [ ['08/31/2006 21:59:59'] => undef, ], now => '2453979 79199', to_sql_value => q{TO_DATE(?,'J SSSSS')}, { method => 'do_iterate', compute_params => sub { my(undef, $params) = @_; $counter = 0; return $params; }, compute_return => sub {[$counter]}, } => [ [sub {++$counter}, Date('1/1/2009'), Date('1/3/2009')] => 3, [sub {$counter++}, Date('1/1/2009'), Date('1/3/2009')] => 1, ], ], ];