Time and Random FunctionsCosmTimeSyntax#include "cosm/time.h" s32 CosmTime( cosmtime * dest, cosm_TIME_CORRECTION * corrections ); DescriptionGet the current time, already synchronized with network time. Compensate for system clock drift and correct accordingly. Return ValuesCOSM_PASS on success, or COSM_FAIL on failure. ErrorsPossible causes of failure:
ExampleCosmTimeSetSyntax#include "cosm/time.h" s32 CosmTimeSet( cosm_TIME_CORRECTION * corrections, u32 * ip_list, u32 ip_count ); DescriptionSynchronize with network time. Don't attempt to set the system clock even though that would be nice. Set the value of time_offset and related values relative to the system clock instead. Use the ip_list as the list of time servers to sync with. Return ValuesCOSM_PASS on success, or COSM_FAIL on failure. ErrorsNone. ExampleCosmTimeUnitsGregorianSyntax#include "cosm/time.h" s32 CosmTimeUnitsGregorian( cosm_TIME_UNITS * units, cosmtime time ); DescriptionFill in the units structure with the time in Gregorian format. The structure of cosm_TIME_UNITS is as follows: typedef struct cosm_TIME_UNITS { /* all values are zero based */ s64 year; /* year */ u32 month; /* month */ u32 day; /* day of month */ u32 wday; /* day of week */ u32 yday; /* day of year */ u32 hour; /* hours */ u32 min; /* minutes */ u32 sec; /* seconds */ u64 subsec; /* sub-seconds, note: unsigned unlike cosmtime */ } cosm_TIME_UNITS; Users will probably find the predefined arrays COSM_TIME_MONTHS, COSM_TIME_MONTHS3, COSM_TIME_DAYS, and COSM_TIME_DAYS3 useful, see example. Return ValuesCOSM_PASS on success, or COSM_FAIL on failure. ErrorsPossible causes of failure:
Examplecosmtime mytime; cosm_TIME_UNITS myunits; const ascii * days[7] = COSM_TIME_DAYS3; const ascii * months[12] = COSM_TIME_MONTHS; u64 milli; milli = 0x004189374BC6A7EFLL; if ( CosmSystemClock( &mytime ) == COSM_PASS ) { if ( CosmTimeUnitsGregorian( &myunits, mytime ) == COSM_PASS ) { CosmPrint( "%.9s %.9s %u, %j %02u:%02u:%02u.%03v UTC, d%u\n", days[myunits.wday], months[myunits.month], myunits.day + 1, myunits.year, myunits.hour, myunits.min, myunits.sec, ( myunits.subsec / milli ), myunits.yday + 1 ); } } CosmTimeDigestGregorianSyntax#include "cosm/time.h" s32 CosmTimeDigestGregorian( cosmtime * time, const cosm_TIME_UNITS * const units ); DescriptionConvert back to a cosmtime value from Gregorian, sanity check the values. Return ValuesCOSM_PASS on success, or COSM_FAIL on failure. ErrorsPossible causes of failure:
Example
© Copyright Mithral Communications & Design Inc.
1995-2025.
All rights reserved.
Mithral® and Cosm® are trademarks of
Mithral Communications & Design Inc.
|