use warnings; use strict; use Getopt::Long; use File::Basename; use Time::Local; our $VERSION = '1.01'; my $debug = 1; main(); sub main { my %opt; GetOptions('help' => \$opt{help}, 'nano2human=s' => \$opt{nano2human}, 'human2nano=s' => \$opt{human2nano}, ) or die "Errors encountered while parsing command line options: $! -- $^E\n"; parse_args(\%opt); if ($opt{nano2human}) { print_help("Malformed nano time (non-digits found): $opt{nano2human}\n") if $opt{nano2human} =~ /\D/; nano2human($opt{nano2human}); } if ($opt{human2nano}) { human2nano($opt{human2nano}); } } sub print_help { my @message = @_; my $script_name = basename $0; print <{help}; unless ($opt->{nano2human} or $opt->{human2nano}) { print_help("Warning: Please specify either --nano2human, --human2nano or both\n"); } } sub win_to_unix_epoch { # Actually hundreds of nanoseconds at this point... my $nanoseconds = shift; # Get seconds my $seconds = $nanoseconds / 10_000_000; # This magic number is the difference between Unix and Windows epoch. my $unix_epoch = $seconds - 11644473600; # Return the Unix epoch for use with localtime(). return $unix_epoch; } sub unix_to_win_epoch { my $unix_epoch = shift; my $winseconds = $unix_epoch + 11644473600; my $win_epoch = sprintf '%.0f', ($winseconds * 10_000_000); return $win_epoch; }