Using External Scripts to Perform Date Time and Unit Conversion

ODTK ships with a DataPicker Control that allows external scripts to perform Date Time and Unit conversions using the same rules and leap second awareness that is built into ODTK and STK. Here are examples of using it in Javascript, VB Script, and Perl.

Javascript Example

var unitPickerObj = null;

function convertDateTime(inpStr,inpUnit,retUnit)
{
        if(unitPickerObj==null)
        {
                unitPickerObj = WScript.CreateObject("AgUiUnitPicker6.AgUiDatePickerCtrl");
                //Optionally set alternative LeapSecond.dat file if it differs from the default location (below)
                //unitPickerObj.LoadLeapSecondTable('C:/ProgramData/AGI/ODTK 6/DynamicEarthData/LeapSecond.dat');
                unitPickerObj.ReadOnly = false;
        }

        unitPickerObj.unit = inpUnit;
        unitPickerObj.returnUnit = inpUnit;
        unitPickerObj.value  = inpStr+"";
        unitPickerObj.returnUnit = retUnit;
        return unitPickerObj.value+"";

}

var x = convertDateTime("2012-05-16T11:12:13.456Z","ISO-YMD","JDate");
var y = parseFloat(x)+2.5;
var z = convertDateTime(y,"JDate","ISO-YMD");
WScript.Echo("z = " + z);

VB Script Example

set unitPickerObj = WScript.CreateObject("AgUiUnitPicker6.AgUiDatePickerCtrl")
unitPickerObj.ReadOnly = false

Function convertDateTime(inpStr,inpUnit,retUnit)

        unitPickerObj.unit = inpUnit
        unitPickerObj.returnUnit = inpUnit
        unitPickerObj.value  = CStr(inpStr)
        unitPickerObj.returnUnit = retUnit
        convertDateTime = CStr(unitPickerObj.value)

End function

x = convertDateTime("2012-05-16T11:12:13.456Z","ISO-YMD","JDate")
y = CDbl(x)+2.5
z = convertDateTime(y,"JDate","ISO-YMD")
WScript.Echo("z = " + z)

 

Perl Example

use Win32::OLE;

$unitPickerObj = Win32::OLE->new('AgUiUnitPicker6.AgUiDatePickerCtrl') or die "oops\n";
$unitPickerObj->{ReadOnly} = false;

sub convertDateTime
{
        my ($inpStr,$inpUnit,$retUnit) = @_;

        $unitPickerObj->{unit} = $inpUnit;
        $unitPickerObj->{returnUnit} = $inpUnit;
        $unitPickerObj->{value}  = $inpStr;
        $unitPickerObj->{returnUnit} = $retUnit;
        return $unitPickerObj->{value};
}

$x = convertDateTime("2012-05-16T11:12:13.456Z","ISO-YMD","JDate");
$y = $x+2.5;
$z = convertDateTime($y,"JDate","ISO-YMD");
print "z = $z";

 

ODTK 6.5