VMX::Common::mysql2time(), ::mysqllocaltime()

databind
vitalif 2009-02-14 00:27:15 +00:00 committed by Vitaliy Filippov
parent 1b3b074c50
commit 61594504f4
1 changed files with 17 additions and 1 deletions

View File

@ -14,6 +14,7 @@ use DBI;
use Digest::MD5;
use Date::Parse;
use Date::Manip;
use POSIX qw(mktime);
use I18N::Langinfo qw(langinfo CODESET);
require Exporter;
@ -22,7 +23,7 @@ our @EXPORT_OK = qw(
quotequote min max trim htmlspecialchars strip_tags strip_unsafe_tags
file_get_contents dbi_hacks ar1el filemd5 mysql_quote updaterow_hashref
insertall_hashref deleteall_hashref dumper_no_lf str2time callif urandom
normalize_url utf8on
normalize_url utf8on mysql2time mysqllocaltime
);
our %EXPORT_TAGS = (all => [ @EXPORT_OK ]);
@ -544,5 +545,20 @@ sub utf8on
return $_[0];
}
# преобразование mysql даты/времени в UNIX время
sub mysql2time { mktime(mysqllocaltime(@_)) }
# и в struct tm
sub mysqllocaltime
{
my ($date, $time) = @_;
$time ||= '';
if ("$date $time" =~ /^(\d+)-(\d+)-(\d+)(?:\s+(\d+):(\d+):(\d+))?/so)
{
return (int($6), int($5), int($4), int($3), int($2)-1, int($1)-1900);
}
return ();
}
1;
__END__