[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[UDUNITS #CNF-843793]: udunits2 conversion


> Hi there I have been trying to convert
> FROM  "734662 days since 1-1-1 00:00:0.0" TO "2012-06-07 00:00:0.0"
> OR
> FROM  "734669.5 days since 1-1-1 00:00:0.0 TO "2012-06-14
> 12:00:0.0"
> It not very obvious how to achieve  this with udunits2.
> Is this conversion possible ?

Assuming you want to perform the conversion programatically:

    ut_system unitSystem = ut_read_xml(NULL);
    ut_unit fromUnit = ut_parse(unitSystem, "734662 days since 1-1-1 
00:00:0.0", UT_ASCII);
    ut_unit toUnit = ut_parse(unitSystem, "days since 2012-06-07 00:00:0.0", 
    cv_converter converter = ut_get_converter(fromUnit, toUnit);
    double fromValue = ...;
    double toValue = cv_convert_double(converter, fromValue);

Note that, due the change in calendars from Julian to Gregorian, converting 
values from a "unit" that's referenced to 1-1-1T00:00:00 to one that referenced 
to a contemporary time can be problematical. Neither UDUNITS package was 
intended for rigorous calendar conversions. For that you should use a package 
intended for that purpose.

> Many thanks
> .. Henry

Steve Emmerson

Ticket Details
Ticket ID: CNF-843793
Department: Support UDUNITS
Priority: Normal
Status: Closed