aboutsummaryrefslogtreecommitdiffstats
path: root/perl/Git.pm
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-02-14 10:29:44 -0800
committerJunio C Hamano <gitster@pobox.com>2013-02-14 10:29:44 -0800
commit01e1406100cff1cc9d1ad2f0c766aaa8c55ebc27 (patch)
treef7fbf235fd6b43678312cadcf98af0594d14558c /perl/Git.pm
parentba56d7057a5da9eb3485391658ba7465c855a8f3 (diff)
parent48c916285753907b71a0ef663576f01ee260095c (diff)
downloadgit-01e1406100cff1cc9d1ad2f0c766aaa8c55ebc27.tar.gz
Merge branch 'bw/get-tz-offset-perl'
* bw/get-tz-offset-perl: cvsimport: format commit timestamp ourselves without using strftime perl/Git.pm: fix get_tz_offset to properly handle DST boundary cases Move Git::SVN::get_tz to Git::get_tz_offset
Diffstat (limited to 'perl/Git.pm')
-rw-r--r--perl/Git.pm23
1 files changed, 23 insertions, 0 deletions
diff --git a/perl/Git.pm b/perl/Git.pm
index 931047c51d..a56d1e76f7 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -59,6 +59,7 @@ require Exporter;
command_bidi_pipe command_close_bidi_pipe
version exec_path html_path hash_object git_cmd_try
remote_refs prompt
+ get_tz_offset
temp_acquire temp_release temp_reset temp_path);
@@ -102,6 +103,7 @@ use Error qw(:try);
use Cwd qw(abs_path cwd);
use IPC::Open2 qw(open2);
use Fcntl qw(SEEK_SET SEEK_CUR);
+use Time::Local qw(timegm);
}
@@ -511,6 +513,27 @@ C<git --html-path>). Useful mostly only internally.
sub html_path { command_oneline('--html-path') }
+
+=item get_tz_offset ( TIME )
+
+Return the time zone offset from GMT in the form +/-HHMM where HH is
+the number of hours from GMT and MM is the number of minutes. This is
+the equivalent of what strftime("%z", ...) would provide on a GNU
+platform.
+
+If TIME is not supplied, the current local time is used.
+
+=cut
+
+sub get_tz_offset {
+ # some systmes don't handle or mishandle %z, so be creative.
+ my $t = shift || time;
+ my $gm = timegm(localtime($t));
+ my $sign = qw( + + - )[ $gm <=> $t ];
+ return sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
+}
+
+
=item prompt ( PROMPT , ISPASSWORD )
Query user C<PROMPT> and return answer from user.