Skip to content

File utctime.cu

FileList > src > utctime.cu

Go to the source code of this file

  • #include "utctime.h"

Public Functions

Type Name
double date_string_to_s (std::string datetime, std::string refdate)
Convert a date string to seconds from a reference date. Converts a date string in the format "YYYY-MM-DDTHH:MM:SS" or "YYYY/MM/DD HH:MM:SS" to seconds from the reference date.
long long date_string_to_time (std::string date)
Convert a date string to a Unix timestamp. Converts a date string in the format "YYYY-MM-DDTHH:MM:SS" or "YYYY/MM/DD HH:MM:SS" to a Unix timestamp (number of seconds since the beginning of 1970 CE).
int days_from_epoch (int y, int m, int d)
Calculate the number of days from the epoch (1970-01-01) to a given date. Algorithm: http://howardhinnant.github.io/date_algorithms.html .
struct tm * gmtime_r (const time_t * timep, struct tm * tm)
Convert a Unix timestamp to a Gregorian civil date-time tuple.
double readinputtimetxt (std::string input, std::string & refdate)
Read a time string and convert it to seconds. Reads a time string and converts it to seconds. If the string is a valid datetime string it returns the seconds from the reference date, otherwise it returns a float of seconds.
bool testime1 (int hour)
Test time calculation functions. Test time calculation functions.
bool testime2 (int hour)
Test time calculation functions for greater than comparison. Test time calculation functions for greater than comparison.
long long timegm (struct tm const * t)
Convert a Gregorian civil date-time tuple to a Unix timestamp. Converts a Gregorian civil date-time tuple in GMT (UTC) time zone to a Unix timestamp.

Public Functions Documentation

function date_string_to_s

Convert a date string to seconds from a reference date. Converts a date string in the format "YYYY-MM-DDTHH:MM:SS" or "YYYY/MM/DD HH:MM:SS" to seconds from the reference date.

double date_string_to_s (
    std::string datetime,
    std::string refdate
) 

Parameters:

  • datetime The date string to convert
  • refdate The reference date string

Returns:

The number of seconds from the reference date as double


function date_string_to_time

Convert a date string to a Unix timestamp. Converts a date string in the format "YYYY-MM-DDTHH:MM:SS" or "YYYY/MM/DD HH:MM:SS" to a Unix timestamp (number of seconds since the beginning of 1970 CE).

long long date_string_to_time (
    std::string date
) 

Parameters:

  • date The date string to convert

Returns:

The corresponding Unix timestamp as long long


function days_from_epoch

Calculate the number of days from the epoch (1970-01-01) to a given date. Algorithm: http://howardhinnant.github.io/date_algorithms.html .

int days_from_epoch (
    int y,
    int m,
    int d
) 

Parameters:

  • y Year
  • m Month
  • d Day

function gmtime_r

Convert a Unix timestamp to a Gregorian civil date-time tuple.

struct tm * gmtime_r (
    const time_t * timep,
    struct tm * tm
) 

Converts a Unix timestamp (number of seconds since the beginning of 1970 CE) to a Gregorian civil date-time tuple in GMT (UTC) time zone.

This conforms to C89 (and C99...) and POSIX.

This implementation works, and doesn't overflow for any sizeof(time_t). It doesn't check for overflow/underflow in tm->tm_year output. Other than that, it never overflows or underflows. It assumes that that time_t is signed.

This implements the inverse of the POSIX formula (http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_15) for all time_t values, no matter the size, as long as tm->tm_year doesn't overflow or underflow. The formula is: tm_sec + tm_min*60 + tm_hour*3600 * tm_yday*86400 + (tm_year-70)*31536000 + ((tm_year-69)/4)*86400 - ((tm_year-1)/100)*86400 + ((tm_year+299)/400)*86400.

Parameters:

  • timep Pointer to the Unix timestamp
  • tm Pointer to the struct tm to be filled

Returns:

Pointer to the filled struct tm


function readinputtimetxt

Read a time string and convert it to seconds. Reads a time string and converts it to seconds. If the string is a valid datetime string it returns the seconds from the reference date, otherwise it returns a float of seconds.

double readinputtimetxt (
    std::string input,
    std::string & refdate
) 

Parameters:

  • input The input time string
  • refdate The reference date string

Returns:

The time in seconds as double


function testime1

Test time calculation functions. Test time calculation functions.

bool testime1 (
    int hour
) 

Parameters:

  • hour The hour to test

function testime2

Test time calculation functions for greater than comparison. Test time calculation functions for greater than comparison.

bool testime2 (
    int hour
) 

Parameters:

  • hour The hour to test

function timegm

Convert a Gregorian civil date-time tuple to a Unix timestamp. Converts a Gregorian civil date-time tuple in GMT (UTC) time zone to a Unix timestamp.

long long timegm (
    struct tm const * t
) 

Note:

It does not modify broken-down time

Parameters:

  • t Pointer to the struct tm to be converted

Returns:

The corresponding Unix timestamp



The documentation for this class was generated from the following file src/utctime.cu