Commit 224de230 authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Add TBDateStringGMT() and TBDateStringLocal() to parse dates and return

appropriate strings in the desired format. We have variants of these
scattered around in too many places.
parent 47a3e1ba
...@@ -37,13 +37,15 @@ use Exporter; ...@@ -37,13 +37,15 @@ use Exporter;
TBSCRIPTLOCK_IGNORE TBSCRIPTLOCK_FAILED TBSCRIPTLOCK_IGNORE TBSCRIPTLOCK_FAILED
PROJROOT GROUPROOT USERROOT SCRATCHROOT SHAREROOT PROJROOT GROUPROOT USERROOT SCRATCHROOT SHAREROOT
TBValidUserDir TBValidUserDirList TBMakeTempFile NewUUID System TBValidUserDir TBValidUserDirList TBMakeTempFile NewUUID System
SendProjAdminMail ReOpenLog SendProjAdminMail ReOpenLog TBDateStringGMT TBDateStringLocal
CheckDaemonRunning MarkDaemonRunning MarkDaemonStopped); CheckDaemonRunning MarkDaemonRunning MarkDaemonStopped);
# After package decl. # After package decl.
use English; use English;
use POSIX qw(strftime); use POSIX qw(strftime);
use POSIX qw(setsid); use POSIX qw(setsid);
use Date::Parse;
use Time::Local;
use Fcntl; use Fcntl;
use Fcntl ':flock'; use Fcntl ':flock';
use File::Basename; use File::Basename;
...@@ -331,6 +333,33 @@ sub TBDateTimeFSSafe() ...@@ -331,6 +333,33 @@ sub TBDateTimeFSSafe()
return POSIX::strftime("20%y%m%d-%H.%M.%S", localtime()); return POSIX::strftime("20%y%m%d-%H.%M.%S", localtime());
} }
# Convert date to GMT
sub TBDateStringGMT($)
{
my ($date) = @_;
return ""
if (!defined($date) || "$date" eq "");
if ($date !~ /^\d$/) {
$date = str2time($date);
}
return POSIX::strftime("20%y-%m-%dT%H:%M:%SZ", gmtime($date));
}
# Convert date to Local
sub TBDateStringLocal($)
{
my ($date) = @_;
return ""
if (!defined($date) || "$date" eq "");
if ($date !~ /^\d*$/) {
$date = timelocal(strptime($date));
}
return POSIX::strftime("20%y-%m-%d %H:%M:%S", localtime($date));
}
# #
# Print out a timestamp if the TIMESTAMPS configure variable was set. # Print out a timestamp if the TIMESTAMPS configure variable was set.
# #
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment