File Coverage

lib/SMB/Time.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition 2 4 50.0
subroutine 5 5 100.0
pod 2 2 100.0
total 22 24 91.6


line stmt bran cond sub pod time code
1             # SMB-Perl library, Copyright (C) 2014 Mikhael Goikhman, migo@cpan.org
2             #
3             # This program is free software: you can redistribute it and/or modify
4             # it under the terms of the GNU General Public License as published by
5             # the Free Software Foundation, either version 3 of the License, or
6             # (at your option) any later version.
7             #
8             # This program is distributed in the hope that it will be useful,
9             # but WITHOUT ANY WARRANTY; without even the implied warranty of
10             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11             # GNU General Public License for more details.
12             #
13             # You should have received a copy of the GNU General Public License
14             # along with this program. If not, see .
15              
16             package SMB::Time;
17              
18 5     5   729 use strict;
  5         9  
  5         177  
19 5     5   27 use warnings;
  5         8  
  5         152  
20              
21             # bigint conflicts with Time::HiRes::time, prefer to lose precision for now
22             #use if (1 << 32 == 1), 'bigint'; # support native uint64 on 32-bit platforms
23              
24 5     5   24 use Exporter 'import';
  5         9  
  5         664  
25             our @EXPORT = qw(from_nttime to_nttime);
26              
27             my $nttime_factor = 10_000_000;
28             my $nttime_offset = 11_644_473_600;
29              
30             sub from_nttime ($) {
31 2   50 2 1 506 my $nttime = shift || return 0;
32              
33 2         9 return $nttime / $nttime_factor - $nttime_offset;
34             }
35              
36             sub to_nttime ($) {
37 34   50 34 1 499 my $time = shift || return 0;
38              
39 34         175 return ($time + $nttime_offset) * $nttime_factor;
40             }
41              
42             1;
43              
44             __END__