#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <pwd.h>
#include <unistd.h>
#include <sys/time.h>
#include "xsh_time.h"
Go to the source code of this file.
Defines | |
#define | MAX_NAME_SIZE 4096 |
#define | GET_CENTURY(d) (int) ( (d) / 1000000L) |
#define | GET_CCYEAR(d) (int) ( (d) / 10000L) |
#define | GET_YEAR(d) (int) (((d) % 1000000L) / 10000L) |
#define | GET_MONTH(d) (int) (((d) % 10000L) / 100) |
#define | GET_DAY(d) (int) ( (d) % 100) |
#define | GET_HOUR(t) (int) ( (t) / 1000000L) |
#define | GET_MINUTE(t) (int) (((t) % 1000000L) / 10000L) |
#define | GET_SECOND(t) (int) (((t) % 10000L) / 100) |
#define | GET_CENTI(t) (int) ( (t) % 100) |
#define | MAKE_DATE(c, y, m, d) |
#define | MAKE_TIME(h, m, s, c) |
#define | INTERVAL_CENTI 1 |
#define | INTERVAL_SEC 100 |
#define | INTERVAL_MIN 6000 |
#define | INTERVAL_HOUR 360000L |
#define | INTERVAL_DAY 8640000L |
Functions | |
static long | timer_to_date (time_t time_secs) |
Converts a timer value to a date. | |
static long | timer_to_time (time_t time_secs) |
Convert a timer value to a time. | |
static long | xsh_time_now (void) |
Returns the current time as a long (HHMMSSCC). | |
static long | xsh_date_now (void) |
Returns the current date as a long (CCYYMMDD). | |
char * | xsh_get_datetime_iso8601 (void) |
Returns the current date and time as a static string. |
#define GET_CCYEAR | ( | d | ) | (int) ( (d) / 10000L) |
Definition at line 52 of file xsh_time.c.
Referenced by xsh_get_datetime_iso8601().
#define GET_CENTI | ( | t | ) | (int) ( (t) % 100) |
Definition at line 67 of file xsh_time.c.
#define GET_CENTURY | ( | d | ) | (int) ( (d) / 1000000L) |
Definition at line 50 of file xsh_time.c.
#define GET_DAY | ( | d | ) | (int) ( (d) % 100) |
Definition at line 58 of file xsh_time.c.
Referenced by xsh_get_datetime_iso8601().
#define GET_HOUR | ( | t | ) | (int) ( (t) / 1000000L) |
Definition at line 61 of file xsh_time.c.
Referenced by xsh_get_datetime_iso8601().
#define GET_MINUTE | ( | t | ) | (int) (((t) % 1000000L) / 10000L) |
Definition at line 63 of file xsh_time.c.
Referenced by xsh_get_datetime_iso8601().
#define GET_MONTH | ( | d | ) | (int) (((d) % 10000L) / 100) |
Definition at line 56 of file xsh_time.c.
Referenced by xsh_get_datetime_iso8601().
#define GET_SECOND | ( | t | ) | (int) (((t) % 10000L) / 100) |
Definition at line 65 of file xsh_time.c.
Referenced by xsh_get_datetime_iso8601().
#define GET_YEAR | ( | d | ) | (int) (((d) % 1000000L) / 10000L) |
Definition at line 54 of file xsh_time.c.
#define INTERVAL_CENTI 1 |
Definition at line 79 of file xsh_time.c.
#define INTERVAL_DAY 8640000L |
Definition at line 83 of file xsh_time.c.
#define INTERVAL_HOUR 360000L |
Definition at line 82 of file xsh_time.c.
#define INTERVAL_MIN 6000 |
Definition at line 81 of file xsh_time.c.
#define INTERVAL_SEC 100 |
Definition at line 80 of file xsh_time.c.
Definition at line 70 of file xsh_time.c.
Referenced by timer_to_date().
Definition at line 74 of file xsh_time.c.
Referenced by timer_to_time().
#define MAX_NAME_SIZE 4096 |
Definition at line 44 of file xsh_time.c.
Referenced by xsh_get_datetime_iso8601().
static long timer_to_date | ( | time_t | time_secs | ) | [static] |
Converts a timer value to a date.
time_secs | Current time definition in seconds. |
Converts the supplied timer value into a long date value. Dates are stored as long values: CCYYMMDD. If the supplied value is zero, returns zero. If the supplied value is out of range, returns 1 January, 1970 (19700101). The timer value is assumed to be UTC (GMT).
Definition at line 191 of file xsh_time.c.
References MAKE_DATE.
Referenced by xsh_date_now().
static long timer_to_time | ( | time_t | time_secs | ) | [static] |
Convert a timer value to a time.
time_secs | Current time definition in seconds. |
Converts the supplied timer value into a long time value. Times are stored as long values: HHMMSS00. Since the timer value does not hold centiseconds, these are set to zero. If the supplied value was zero or invalid, returns zero. The timer value is assumed to be UTC (GMT).
Definition at line 225 of file xsh_time.c.
References MAKE_TIME.
Referenced by xsh_time_now().
static long xsh_date_now | ( | void | ) | [static] |
Returns the current date as a long (CCYYMMDD).
Returns the current date as a long value (CCYYMMDD). Since most system clocks do not return a century, this function assumes that all years 80 and above are in the 20th century, and all years 00 to 79 are in the 21st century. For best results, consume before 1 Jan 2080. Example: 19 Oct 2000 is returned as 20001019
Definition at line 153 of file xsh_time.c.
References timer_to_date().
Referenced by xsh_get_datetime_iso8601().
static long xsh_time_now | ( | void | ) | [static] |
Returns the current time as a long (HHMMSSCC).
Returns the current time as a long value (HHMMSSCC). If the system clock does not return centiseconds, these are set to zero.
Example: 15:36:12.84 is returned as 15361284
Definition at line 169 of file xsh_time.c.
References timer_to_time().
Referenced by xsh_get_datetime_iso8601().