1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#! /bin/sh
#BEGIN DEPEND------------------------------------------------------------------
INPUT_MODULES='src/lib/perl5/COD/CIF/Data/Check.pm'
#END DEPEND--------------------------------------------------------------------
perl <<'END_SCRIPT'
#------------------------------------------------------------------------------
#$Author: antanas $
#$Date: 2021-07-30 19:52:52 +0300 (Fri, 30 Jul 2021) $
#$Revision: 8840 $
#$URL: svn+ssh://www.crystallography.net/home/coder/svn-repositories/cod-tools/tags/v3.7.0/tests/shtests/parse_datetime_002.sh $
#------------------------------------------------------------------------------
#*
#* Unit test for the COD::CIF::Data::Check::parse_datetime() subroutine.
#* Tests how various timestamp strings that do not correspond to the
#* required format are handled.
#**
use strict;
use warnings;
use COD::CIF::Data::Check;
my @datetime_values = (
# Overall incorrect date format
'This is a text string',
# Month lies outside the [1, 12] range
'2000-23-01',
# Day lies outside the allowed range for the given month
'2000-02-30',
# Space in front of the date-only timestamp
' 2000-02-30',
# Space at the end of the date-only timestamp
'2000-02-30 ',
# Space in front of the datetime timestamp
' 1985-04-12T23:20:50.52Z',
# Space at the end of the datetime timestamp
'1985-04-12T23:20:50.52Z ',
# Incorrect datetime
'1985-04-12T23:20:50.52J',
# Space instead of the 'T' separator
'1985-04-12 23:20:50.52Z',
);
for (@datetime_values) {
eval {
my $dt = COD::CIF::Data::Check::parse_datetime($_);
print $dt->datetime . "\n";
};
if ($@) {
print "Value '$_' could not be successfully parsed as a timestamp value.\n";
}
}
END_SCRIPT
|