diff options
author | Frédéric Buclin <LpSolit@netscape.net> | 2017-08-02 12:59:20 +0200 |
---|---|---|
committer | Frédéric Buclin <LpSolit@netscape.net> | 2017-08-02 12:59:20 +0200 |
commit | 8d9c748a5e694fb544c082128c9756a0ca702334 (patch) | |
tree | bdbeb505e609ecba2861aa666b7f8ef157ba2c5d /extensions/Mageia/lib/Util.pm | |
parent | 775362d8fb630da4fbb1e3f75c45183fd0a28667 (diff) | |
download | bugs-8d9c748a5e694fb544c082128c9756a0ca702334.tar bugs-8d9c748a5e694fb544c082128c9756a0ca702334.tar.gz bugs-8d9c748a5e694fb544c082128c9756a0ca702334.tar.bz2 bugs-8d9c748a5e694fb544c082128c9756a0ca702334.tar.xz bugs-8d9c748a5e694fb544c082128c9756a0ca702334.zip |
Implement inline history
Diffstat (limited to 'extensions/Mageia/lib/Util.pm')
-rw-r--r-- | extensions/Mageia/lib/Util.pm | 24 |
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; |