summaryrefslogtreecommitdiffstats
path: root/extensions/BugModal/lib/Util.pm
diff options
context:
space:
mode:
authorByron Jones <glob@mozilla.com>2015-04-14 07:20:00 +0200
committerByron Jones <glob@mozilla.com>2015-04-14 07:20:00 +0200
commite5131c86c22c5577c0e27db04481084caf635dc5 (patch)
tree897a6ef2d1314a1c442e9e8b8ff14a4dd2cf3eb2 /extensions/BugModal/lib/Util.pm
parent6116f2f7cf32f40c1f943cef3f523ed5955f968d (diff)
downloadbugzilla-e5131c86c22c5577c0e27db04481084caf635dc5.tar.gz
bugzilla-e5131c86c22c5577c0e27db04481084caf635dc5.tar.xz
Bug 1146767: update relative dates without refreshing the page
Diffstat (limited to 'extensions/BugModal/lib/Util.pm')
-rw-r--r--extensions/BugModal/lib/Util.pm31
1 files changed, 31 insertions, 0 deletions
diff --git a/extensions/BugModal/lib/Util.pm b/extensions/BugModal/lib/Util.pm
new file mode 100644
index 000000000..daca86518
--- /dev/null
+++ b/extensions/BugModal/lib/Util.pm
@@ -0,0 +1,31 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+package Bugzilla::Extension::BugModal::Util;
+use strict;
+use warnings;
+
+use base qw(Exporter);
+our @EXPORT_OK = qw(date_str_to_time);
+
+use feature 'state';
+
+use Bugzilla::Util qw(datetime_from);
+use DateTime::TimeZone;
+use Time::Local qw(timelocal);
+
+sub date_str_to_time {
+ my ($date) = @_;
+ # avoid creating a DateTime object
+ if ($date =~ /^(\d{4})[\.\-](\d{2})[\.\-](\d{2}) (\d{2}):(\d{2}):(\d{2})$/) {
+ return timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900);
+ }
+ state $tz //= DateTime::TimeZone->new( name => 'local' );
+ return datetime_from($date, $tz)->epoch;
+}
+
+1;