aboutsummaryrefslogtreecommitdiffstats
path: root/extensions/Mageia/lib/Util.pm
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/Mageia/lib/Util.pm')
-rw-r--r--extensions/Mageia/lib/Util.pm24
1 files changed, 22 insertions, 2 deletions
diff --git a/extensions/Mageia/lib/Util.pm b/extensions/Mageia/lib/Util.pm
index f13ee2091..60447fa28 100644
--- a/extensions/Mageia/lib/Util.pm
+++ b/extensions/Mageia/lib/Util.pm
@@ -13,12 +13,32 @@ use warnings;
use parent qw(Exporter);
-our @EXPORT = qw(
-);
+our @EXPORT = qw(compare_datetimes);
# This file can be loaded by your extension via
# "use Bugzilla::Extension::Mageia::Util". You can put functions
# used by your extension in here. (Make sure you also list them in
# @EXPORT.)
+# Return -1 if $t1 < $t2, 0 if $t1 == $t2, 1 if $t1 > $t2, undef if a date is invalid.
+sub compare_datetimes {
+ my ($t1, $t2) = @_;
+ my (@time1, @time2);
+ if ($t1 =~ /^(\d{4})[\.-](\d{2})[\.-](\d{2})(?: (\d{2}):(\d{2}):(\d{2}))?$/) {
+ @time1 = ($1, $2, $3, $4, $5, $6);
+ }
+ if ($t2 =~ /^(\d{4})[\.-](\d{2})[\.-](\d{2})(?: (\d{2}):(\d{2}):(\d{2}))?$/) {
+ @time2 = ($1, $2, $3, $4, $5, $6);
+ }
+ return undef unless scalar(@time1) && scalar(@time2);
+
+ for my $i (0..5) {
+ $t1 = $time1[$i] // 0;
+ $t2 = $time2[$i] // 0;
+ next if $t1 == $t2;
+ return $t1 <=> $t2;
+ }
+ return 0;
+}
+
1;