#!/usr/bin/perl
#
# lvdate.pl - convert labview timestamp into a readable date/time string
#
# usage: lvdate.pl nnnnnnnnn  -or- lvdate.pl nnnnn mmmmmm
#

use POSIX;

sub usage {
   warn "Usage: lvdate.pl <timestamp>\n",
        "  where <timestamp> is either a single 32-bit decimal number or a\n",
        "  pair of 16-bit decimal numbers representing the LabView timestamp.",
        "\n";
}

our $timestamp;

if (@ARGV < 1) {
   usage();
   exit 1;
}
elsif (@ARGV < 2) {
   $timestamp = $ARGV[0];
}
else {
   $timestamp = $ARGV[0]*(1<<16)+$ARGV[1];
}

my $sec=0;
my $min=0;
my $hour=0;
my $day=1;
my $mon=1 -1;
my $year=1904 -1900;
my $wday=0;
my $yday=0;
my $epoch = mktime($sec,$min,$hour,$day,$mon,$year,$wday,$yday);
print scalar localtime($timestamp+$epoch);
print "\n";
