| 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 <http://www.gnu.org/licenses/>. | ||
| 15 | |||
| 16 | package SMB::Time; | ||
| 17 | |||
| 18 | use strict; | ||
| 19 | use warnings; | ||
| 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 | use Exporter 'import'; | ||
| 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 | my $nttime = shift || return 0; | ||
| 32 | |||
| 33 | return $nttime / $nttime_factor - $nttime_offset; | ||
| 34 | } | ||
| 35 | |||
| 36 | sub to_nttime ($) { | ||
| 37 | my $time = shift || return 0; | ||
| 38 | |||
| 39 | return ($time + $nttime_offset) * $nttime_factor; | ||
| 40 | } | ||
| 41 | |||
| 42 | 1; | ||
| 43 | |||
| 44 | __END__ |