FARGOS/VISTA Object Management Environment Core  ..
FARGOS/VISTA Object Management Environment Core Table of Contents
TimePointOfGranularity< UNITS > Class Template Reference

Representation of localized expanded UNITS-since-epoch. More...

#include <time_point.hpp>

Public Types

enum  { OUTPUT_DATE =1, OUTPUT_TIME =2 }
 

Public Member Functions

void initializeWithUnitsFromEpoch (time_t secondsSinceEpoch, uint64_t fractionInUnits, int skewByMinutes=0, const TimePointCache *cachedTimeInfo=&TimePointCacheForToday)
 Initialize with seconds from POSIX epoch, fractional component and optional skew from localtime. More...
 
void initializeWithNanosecondsFromEpoch (uint64_t nanosecondsSinceEpoch, time_t secondsSinceEpoch=0, const TimePointCache *cachedTimeInfo=&TimePointCacheForToday, int skewByMinutes=0) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3")
 Initialize with time specified as nanoseconds from POSIX epoch. More...
 
 TimePointOfGranularity ()
 Null constructor, leaves in undefined state. More...
 
 TimePointOfGranularity (const struct tm &explodedTime, uint64_t fraction=0)
 Construct from standard broken-out time structure. More...
 
template<unsigned int PT_UNITS>
 TimePointOfGranularity (const POSIXtimeInUnits< PT_UNITS > ptTime, const TimePointCache *cachedTimeInfo=&TimePointCacheForToday, int skewByMinutes=0)
 Construct from arbitrary POSIXtimeInUnits<> object. More...
 
 TimePointOfGranularity (const char *dayAndTime, const TimePointCache *cachedTimeInfo=&TimePointCacheForToday)
 Construct from text string specifying date and time. More...
 
 TimePointOfGranularity (const char *day, const char *timeOfDay, const TimePointCache *cachedTimeInfo=&TimePointCacheForToday)
 Construct from text string specifying date and time. More...
 
 TimePointOfGranularity (time_t secondsSinceEpoch, uint64_t fraction=0, int skewByMinutes=0, const TimePointCache *cachedTimeInfo=&TimePointCacheForToday)
 Construct from seconds from POSIX epoch and optional fractional component and skew from localtime. More...
 
template<unsigned int INCOMING_UNITS = UNITS>
TimePointOfGranularity< UNITS > & operator= (const TimePointOfGranularity< INCOMING_UNITS > &arg)
 assignment operator from a TimePointOfGranularity object. More...
 
TimePointOfGranularity< UNITS > & operator= (const struct tm &POSIXexpandedDate)
 assignment operator from a tm structure. More...
 
 operator const struct tm & () const OME_ALWAYS_INLINE
 Cast operator to return reference to tm structure. More...
 
uint64_t convertToNanosecondsSinceEpoch (const TimePointCache *cachedTimeInfo=&TimePointCacheForToday) const
 Convert expanded time to nanoseconds since POSIX epoch. More...
 
uint64_t convertToCustomEpochUnits (uint64_t desired_granularity=UNITS, const TimePointCache *cachedTimeInfo=&TimePointCacheForToday) const
 Convert expanded time to custom units since POSIX epoch. More...
 
uint64_t getRelativeUnitsInDay () const
 Get relative units within a day. More...
 
uint64_t getRelativeMicrosecondsInDay () const
 Get relative microseconds within a day. More...
 
uint64_t getRelativeNanosecondsInDay () const
 Get relative nanoseconds within a day. More...
 
const char * convertDayAndTime (const char *dayAndTime, const TimePointCache *cachedTimeInfo=&TimePointCacheForToday)
 Convert string representing day and time into expanded time structure. More...
 
int convertDayAndTime (const char *day, const char *timeOfDay, const TimePointCache *cachedTimeInfo=&TimePointCacheForToday)
 Convert strings representing date and time into expanded time structure. More...
 
char * formatIntoString (char *bfr, uint_fast8_t bfrLen, uint_fast8_t *resultLen=nullptr, uint_fast8_t fieldsWanted=OUTPUT_DATE|OUTPUT_TIME, const char *fieldSeparators="/:. ") const
 Format into text string. More...
 
template<unsigned int ALT_UNITS>
int compareDate (const TimePointOfGranularity< ALT_UNITS > &arg) const
 Compare the date portion of a TimePointOfGranularity. More...
 

Static Public Member Functions

static CONSTEXPR uint64_t getUnitsPerSecond () OME_CONST_FUNCTION OME_ALWAYS_INLINE
 Get units per second represented by fractional component. More...
 

Public Attributes

struct tm expandedTime
 Locale-specific time, conforms to POSIX, C89 and onwards. More...
 
uint64_t fractionalUnits
 Fractional seconds in granularity of UNITS-per-second. More...
 

Detailed Description

template<unsigned int UNITS>
class TimePointOfGranularity< UNITS >

Representation of localized expanded UNITS-since-epoch.

Note
This template exists only to be able to handle arbitrary granularity of an incoming time unit. Ideally, it would be implemented to consume nanoseconds and variable granularity would not be an issue.

Member Enumeration Documentation

◆ anonymous enum

template<unsigned int UNITS>
anonymous enum
Enumerator
OUTPUT_DATE 
OUTPUT_TIME 

Constructor & Destructor Documentation

◆ TimePointOfGranularity() [1/6]

template<unsigned int UNITS>
TimePointOfGranularity< UNITS >::TimePointOfGranularity ( )
inline

Null constructor, leaves in undefined state.

◆ TimePointOfGranularity() [2/6]

template<unsigned int UNITS>
TimePointOfGranularity< UNITS >::TimePointOfGranularity ( const struct tm &  explodedTime,
uint64_t  fraction = 0 
)
inlineexplicit

Construct from standard broken-out time structure.

Parameters
explodedTimeprovides the desired locale-specific time.
fractionis an optional parameter that specifies the fraction of a second in a granularity of UNITS.

References TimePointOfGranularity< UNITS >::expandedTime, and TimePointOfGranularity< UNITS >::fractionalUnits.

◆ TimePointOfGranularity() [3/6]

template<unsigned int UNITS>
template<unsigned int PT_UNITS>
TimePointOfGranularity< UNITS >::TimePointOfGranularity ( const POSIXtimeInUnits< PT_UNITS >  ptTime,
const TimePointCache cachedTimeInfo = &TimePointCacheForToday,
int  skewByMinutes = 0 
)
inlineexplicit

Construct from arbitrary POSIXtimeInUnits<> object.

Parameters
ptTimespecifies an unambiguous time specified as POSIXtimeInUnits with granularity PT_UNITS.
cachedTimeInfoprovides an TimePointCache object to enable the avoidance of expensive calculations if the time in question is within the range supported by the TimePointCache object.
skewByMinutesis an optional parameter that allows skewing the provided time by the specified number of minutes.

References POSIXtimeInUnits< UNITS >::convertToCustomEpochUnits(), and TimePointOfGranularity< UNITS >::initializeWithUnitsFromEpoch().

◆ TimePointOfGranularity() [4/6]

template<unsigned int UNITS>
TimePointOfGranularity< UNITS >::TimePointOfGranularity ( const char *  dayAndTime,
const TimePointCache cachedTimeInfo = &TimePointCacheForToday 
)
inlineexplicit

Construct from text string specifying date and time.

Parameters
dayAndTimespecifies the date and time as a single contiguous string.
cachedTimeInfopoints to an optional TimePointCache that can be used to accelerate conversions if the date being converted corresponds to the TimePointCache.

References TimePointOfGranularity< UNITS >::convertDayAndTime().

◆ TimePointOfGranularity() [5/6]

template<unsigned int UNITS>
TimePointOfGranularity< UNITS >::TimePointOfGranularity ( const char *  day,
const char *  timeOfDay,
const TimePointCache cachedTimeInfo = &TimePointCacheForToday 
)
inline

Construct from text string specifying date and time.

Parameters
dayspecifies the date
timeOfDayspecifies the time of day (hours, minutes, seconds)
cachedTimeInfois an optional TimePointCache that can be used to accelerate conversions if the date being converted corresponds to the TimePointCache.

References TimePointOfGranularity< UNITS >::convertDayAndTime().

◆ TimePointOfGranularity() [6/6]

template<unsigned int UNITS>
TimePointOfGranularity< UNITS >::TimePointOfGranularity ( time_t  secondsSinceEpoch,
uint64_t  fraction = 0,
int  skewByMinutes = 0,
const TimePointCache cachedTimeInfo = &TimePointCacheForToday 
)
inlineexplicit

Construct from seconds from POSIX epoch and optional fractional component and skew from localtime.

Parameters
secondsSinceEpochprovides the number of seconds since the POSIX epoch.
fractionspecifies the number of fractional units in a partial second. Defaults to 0.
skewByMinutesindicates the number of minutes the expanded time should be shifted from localtime. Defaults to 0.
cachedTimeInfoprovides an optional TimePointCache object to enable the avoidance of expensive calculations if the time in question is within the range supported by the TimePointCache object.

References TimePointOfGranularity< UNITS >::initializeWithUnitsFromEpoch().

Member Function Documentation

◆ compareDate()

template<unsigned int UNITS>
template<unsigned int ALT_UNITS>
int TimePointOfGranularity< UNITS >::compareDate ( const TimePointOfGranularity< ALT_UNITS > &  arg) const
inline

Compare the date portion of a TimePointOfGranularity.

Parameters
argspecifies a TimePointOfGranularity of arbitrary granularity.

The year, month, and day of the month are compared, not the time-of-day component.

References TimePointOfGranularity< UNITS >::expandedTime.

◆ convertDayAndTime() [1/2]

template<unsigned int UNITS>
int TimePointOfGranularity< UNITS >::convertDayAndTime ( const char *  day,
const char *  timeOfDay,
const TimePointCache cachedTimeInfo = &TimePointCacheForToday 
)
inline

Convert strings representing date and time into expanded time structure.

Parameters
daypoints to a text string that holds a date.
timeOfDaypoints to a text string that holds a time.
cachedTimeInfopoints to a TimePointCache object that can be used to accelerate conversion of times that are in UTC.

References TimePointOfGranularity< UNITS >::convertDayAndTime().

◆ convertDayAndTime() [2/2]

template<unsigned int UNITS>
const char* TimePointOfGranularity< UNITS >::convertDayAndTime ( const char *  dayAndTime,
const TimePointCache cachedTimeInfo = &TimePointCacheForToday 
)
inline

Convert string representing day and time into expanded time structure.

Parameters
dayAndTimepoints to a text string that holds a day and time.
cachedTimeInfopoints to a TimePointCache object that can be used to accelerate conversion of times that are in UTC.
Note
The following formats are recognized for days: Y/M/D, Y-M-D, YYYYMMDD, Mon D Y

The following formats are recognized for time: HHMMSS[.fraction][Z] [{AM|PM}], H:M:S[.fraction][Z] [{AM|PM}]

Returns
a pointer to the character after the last character processed by the routine will be returned. Often the last character processsed will be the null character, but it could be whitespace.

References TimePointOfGranularity< UNITS >::expandedTime, TimePointOfGranularity< UNITS >::fractionalUnits, TimePointCache::offsetFromUTC(), and text2uint32().

Referenced by TimePointOfGranularity< UNITS >::convertDayAndTime(), and TimePointOfGranularity< UNITS >::TimePointOfGranularity().

◆ convertToCustomEpochUnits()

template<unsigned int UNITS>
uint64_t TimePointOfGranularity< UNITS >::convertToCustomEpochUnits ( uint64_t  desired_granularity = UNITS,
const TimePointCache cachedTimeInfo = &TimePointCacheForToday 
) const
inline

Convert expanded time to custom units since POSIX epoch.

Parameters
desired_granularityspecifies the granularity of the converted result. It does not have to match the units used by the TimePointOfGranularity representation.
cachedTimeInfospecifies a TimePointCache object that can be used to accelerate the conversion of times within the date covered by the cache object.
Returns
the corresponding units of the desired granularity are returned.

References CALL_TZSET, TimePointOfGranularity< UNITS >::expandedTime, and TimePointOfGranularity< UNITS >::fractionalUnits.

◆ convertToNanosecondsSinceEpoch()

template<unsigned int UNITS>
uint64_t TimePointOfGranularity< UNITS >::convertToNanosecondsSinceEpoch ( const TimePointCache cachedTimeInfo = &TimePointCacheForToday) const
inline

Convert expanded time to nanoseconds since POSIX epoch.

Parameters
cachedTimeInfoprovides an optional TimePointCache object to enable the avoidance of expensive calculations if the time in question is within the range supported by the TimePointCache object.

References CALL_TZSET, TimePointOfGranularity< UNITS >::expandedTime, and TimePointOfGranularity< UNITS >::fractionalUnits.

◆ formatIntoString()

template<unsigned int UNITS>
char* TimePointOfGranularity< UNITS >::formatIntoString ( char *  bfr,
uint_fast8_t  bfrLen,
uint_fast8_t *  resultLen = nullptr,
uint_fast8_t  fieldsWanted = OUTPUT_DATE|OUTPUT_TIME,
const char *  fieldSeparators = "/:. " 
) const
inline

Format into text string.

Parameters
bfrspecifies the output buffer,
bfrLenspecified the length of available space
resultLenis an option pointer to a location into which the length of the result can be stored.
fieldsWantedis a bit mask indicating the desired elements.
fieldSeparatorsis a 4-character string indicating the separator elements between the year/month/day, hour:min:sec, fractional and date vs. time groupings. It defaults to "/:. ". If one of the individual elements is a null character, no separator will be output.

References TimePointOfGranularity< UNITS >::expandedTime, TimePointOfGranularity< UNITS >::fractionalUnits, numberAs4Digits, numberAsTwoDigits, TimePointOfGranularity< UNITS >::OUTPUT_DATE, TimePointOfGranularity< UNITS >::OUTPUT_TIME, and uint_to_ascii_right_justified().

Referenced by LogMessageRecord::formatRecordAsText(), operator<<(), and ReadBinaryLog::outputAssembledLine().

◆ getRelativeMicrosecondsInDay()

template<unsigned int UNITS>
uint64_t TimePointOfGranularity< UNITS >::getRelativeMicrosecondsInDay ( ) const
inline

◆ getRelativeNanosecondsInDay()

template<unsigned int UNITS>
uint64_t TimePointOfGranularity< UNITS >::getRelativeNanosecondsInDay ( ) const
inline

◆ getRelativeUnitsInDay()

template<unsigned int UNITS>
uint64_t TimePointOfGranularity< UNITS >::getRelativeUnitsInDay ( ) const
inline

◆ getUnitsPerSecond()

template<unsigned int UNITS>
static CONSTEXPR uint64_t TimePointOfGranularity< UNITS >::getUnitsPerSecond ( )
inlinestatic

Get units per second represented by fractional component.

◆ initializeWithNanosecondsFromEpoch()

template<unsigned int UNITS>
void TimePointOfGranularity< UNITS >::initializeWithNanosecondsFromEpoch ( uint64_t  nanosecondsSinceEpoch,
time_t  secondsSinceEpoch = 0,
const TimePointCache cachedTimeInfo = &TimePointCacheForToday,
int  skewByMinutes = 0 
)
inline

Initialize with time specified as nanoseconds from POSIX epoch.

Parameters
nanosecondsSinceEpochprovides the number of nanoseconds since the POSIX epoch. This can be the total number of nanoseconds or only the sub-second fraction.
secondsSinceEpochprovides the number of seconds since the POSIX epoch. If the complete number of nanoseconds was provided by nanosecondsSinceEpoch, this will be 0.
cachedTimeInfoprovides a TimePointCache object to enable the avoidance of expensive calculations if the time in question is within the range supported by the TimePointCache object.
skewByMinutesindicates the number of minutes the expanded time should be shifted from localtime. Defaults to 0.

References TimePointOfGranularity< UNITS >::initializeWithUnitsFromEpoch().

◆ initializeWithUnitsFromEpoch()

template<unsigned int UNITS>
void TimePointOfGranularity< UNITS >::initializeWithUnitsFromEpoch ( time_t  secondsSinceEpoch,
uint64_t  fractionInUnits,
int  skewByMinutes = 0,
const TimePointCache cachedTimeInfo = &TimePointCacheForToday 
)
inline

Initialize with seconds from POSIX epoch, fractional component and optional skew from localtime.

Parameters
secondsSinceEpochprovides the number of seconds since the POSIX epoch.
fractionInUnitsspecifies the number of fractional units in a partial second. Values greater than a whole second are accepted. Defaults to 0.
skewByMinutesindicates the number of minutes the expanded time should be shifted from localtime. Defaults to 0.
cachedTimeInfoprovides an optional TimePointCache object to enable the avoidance of expensive calculations if the time in question is within the range supported by the TimePointCache object.

References CALL_TZSET, TimePointOfGranularity< UNITS >::expandedTime, and TimePointOfGranularity< UNITS >::fractionalUnits.

Referenced by TimePointOfGranularity< UNITS >::initializeWithNanosecondsFromEpoch(), and TimePointOfGranularity< UNITS >::TimePointOfGranularity().

◆ operator const struct tm &()

template<unsigned int UNITS>
TimePointOfGranularity< UNITS >::operator const struct tm & ( ) const
inlineexplicit

Cast operator to return reference to tm structure.

References TimePointOfGranularity< UNITS >::expandedTime.

◆ operator=() [1/2]

template<unsigned int UNITS>
TimePointOfGranularity<UNITS>& TimePointOfGranularity< UNITS >::operator= ( const struct tm &  POSIXexpandedDate)
inline

◆ operator=() [2/2]

template<unsigned int UNITS>
template<unsigned int INCOMING_UNITS = UNITS>
TimePointOfGranularity<UNITS>& TimePointOfGranularity< UNITS >::operator= ( const TimePointOfGranularity< INCOMING_UNITS > &  arg)
inline

Member Data Documentation

◆ expandedTime

◆ fractionalUnits


The documentation for this class was generated from the following file:
Generated: Fri Jul 31 2020 18:19:16
Support Information