#include <pgtypes_interval.h>
Go to the source code of this file.
Typedefs | |
typedef double | timestamp |
typedef double | TimestampTz |
Functions | |
timestamp | PGTYPEStimestamp_from_asc (char *, char **) |
char * | PGTYPEStimestamp_to_asc (timestamp) |
int | PGTYPEStimestamp_sub (timestamp *, timestamp *, interval *) |
int | PGTYPEStimestamp_fmt_asc (timestamp *, char *, int, const char *) |
void | PGTYPEStimestamp_current (timestamp *) |
int | PGTYPEStimestamp_defmt_asc (char *, const char *, timestamp *) |
int | PGTYPEStimestamp_add_interval (timestamp *tin, interval *span, timestamp *tout) |
int | PGTYPEStimestamp_sub_interval (timestamp *tin, interval *span, timestamp *tout) |
typedef double timestamp |
Definition at line 13 of file pgtypes_timestamp.h.
typedef double TimestampTz |
Definition at line 14 of file pgtypes_timestamp.h.
Definition at line 949 of file timestamp.c.
References day_tab, isleap, interval::month, MONTHS_PER_YEAR, NULL, interval::time, timestamp2tm(), TIMESTAMP_NOT_FINITE, tm, tm2timestamp(), and pg_tm::tm_mon.
Referenced by main(), and PGTYPEStimestamp_sub_interval().
{ if (TIMESTAMP_NOT_FINITE(*tin)) *tout = *tin; else { if (span->month != 0) { struct tm tt, *tm = &tt; fsec_t fsec; if (timestamp2tm(*tin, NULL, tm, &fsec, NULL) != 0) return -1; tm->tm_mon += span->month; if (tm->tm_mon > MONTHS_PER_YEAR) { tm->tm_year += (tm->tm_mon - 1) / MONTHS_PER_YEAR; tm->tm_mon = (tm->tm_mon - 1) % MONTHS_PER_YEAR + 1; } else if (tm->tm_mon < 1) { tm->tm_year += tm->tm_mon / MONTHS_PER_YEAR - 1; tm->tm_mon = tm->tm_mon % MONTHS_PER_YEAR + MONTHS_PER_YEAR; } /* adjust for end of month boundary problems... */ if (tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]) tm->tm_mday = (day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]); if (tm2timestamp(tm, fsec, NULL, tin) != 0) return -1; } *tin += span->time; *tout = *tin; } return 0; }
void PGTYPEStimestamp_current | ( | timestamp * | ) |
Definition at line 375 of file timestamp.c.
References GetCurrentDateTime(), NULL, tm, and tm2timestamp().
Referenced by dtcurrent(), and main().
{ struct tm tm; GetCurrentDateTime(&tm); if (errno == 0) tm2timestamp(&tm, 0, NULL, ts); return; }
int PGTYPEStimestamp_defmt_asc | ( | char * | , | |
const char * | , | |||
timestamp * | ||||
) |
Definition at line 897 of file timestamp.c.
References free, i, pgtypes_strdup(), and PGTYPEStimestamp_defmt_scan().
Referenced by dtcvfmtasc(), and main().
{ int year, month, day; int hour, minute, second; int tz; int i; char *mstr; char *mfmt; if (!fmt) fmt = "%Y-%m-%d %H:%M:%S"; if (!fmt[0]) return 1; mstr = pgtypes_strdup(str); mfmt = pgtypes_strdup(fmt); /* * initialize with impossible values so that we can see if the fields * where specified at all */ /* XXX ambiguity with 1 BC for year? */ year = -1; month = -1; day = -1; hour = 0; minute = -1; second = -1; tz = 0; i = PGTYPEStimestamp_defmt_scan(&mstr, mfmt, d, &year, &month, &day, &hour, &minute, &second, &tz); free(mstr); free(mfmt); return i; }
int PGTYPEStimestamp_fmt_asc | ( | timestamp * | , | |
char * | , | |||
int | , | |||
const char * | ||||
) |
Definition at line 869 of file timestamp.c.
References dttofmtasc_replace(), NULL, PGTYPESdate_dayofweek(), PGTYPESdate_from_timestamp(), timestamp2tm(), and tm.
Referenced by dttofmtasc(), and main().
{ struct tm tm; fsec_t fsec; date dDate; int dow; dDate = PGTYPESdate_from_timestamp(*ts); dow = PGTYPESdate_dayofweek(dDate); timestamp2tm(*ts, NULL, &tm, &fsec, NULL); return dttofmtasc_replace(ts, dDate, dow, &tm, output, &str_len, fmtstr); }
timestamp PGTYPEStimestamp_from_asc | ( | char * | , | |
char ** | ||||
) |
Definition at line 278 of file timestamp.c.
References DecodeDateTime(), DTK_DATE, DTK_EARLY, DTK_EPOCH, DTK_INVALID, DTK_LATE, MAXDATELEN, NULL, ParseDateTime(), SetEpochTimestamp(), TIMESTAMP_NOBEGIN, TIMESTAMP_NOEND, tm, and tm2timestamp().
Referenced by dtcvasc(), ecpg_get_data(), and main().
{ timestamp result; #ifdef HAVE_INT64_TIMESTAMP int64 noresult = 0; #else double noresult = 0.0; #endif fsec_t fsec; struct tm tt, *tm = &tt; int dtype; int nf; char *field[MAXDATEFIELDS]; int ftype[MAXDATEFIELDS]; char lowstr[MAXDATELEN + MAXDATEFIELDS]; char *realptr; char **ptr = (endptr != NULL) ? endptr : &realptr; if (strlen(str) >= sizeof(lowstr)) { errno = PGTYPES_TS_BAD_TIMESTAMP; return (noresult); } if (ParseDateTime(str, lowstr, field, ftype, &nf, ptr) != 0 || DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, 0) != 0) { errno = PGTYPES_TS_BAD_TIMESTAMP; return (noresult); } switch (dtype) { case DTK_DATE: if (tm2timestamp(tm, fsec, NULL, &result) != 0) { errno = PGTYPES_TS_BAD_TIMESTAMP; return (noresult); } break; case DTK_EPOCH: result = SetEpochTimestamp(); break; case DTK_LATE: TIMESTAMP_NOEND(result); break; case DTK_EARLY: TIMESTAMP_NOBEGIN(result); break; case DTK_INVALID: errno = PGTYPES_TS_BAD_TIMESTAMP; return (noresult); default: errno = PGTYPES_TS_BAD_TIMESTAMP; return (noresult); } /* AdjustTimestampForTypmod(&result, typmod); */ /* * Since it's difficult to test for noresult, make sure errno is 0 if no * error occurred. */ errno = 0; return result; }
Definition at line 884 of file timestamp.c.
References interval::month, interval::time, and TIMESTAMP_NOT_FINITE.
Referenced by dtsub().
{ if (TIMESTAMP_NOT_FINITE(*ts1) || TIMESTAMP_NOT_FINITE(*ts2)) return PGTYPES_TS_ERR_EINFTIME; else iv->time = (*ts1 - *ts2); iv->month = 0; return 0; }
Definition at line 1010 of file timestamp.c.
References interval::month, PGTYPEStimestamp_add_interval(), and interval::time.
char* PGTYPEStimestamp_to_asc | ( | timestamp | ) |
Definition at line 353 of file timestamp.c.
References buf, DateStyle, EncodeDateTime(), EncodeSpecialTimestamp(), MAXDATELEN, NULL, pgtypes_strdup(), timestamp2tm(), TIMESTAMP_NOT_FINITE, and tm.
Referenced by dttoasc(), ecpg_store_input(), and main().
{ struct tm tt, *tm = &tt; char buf[MAXDATELEN + 1]; fsec_t fsec; int DateStyle = 1; /* this defaults to ISO_DATES, shall we make * it an option? */ if (TIMESTAMP_NOT_FINITE(tstamp)) EncodeSpecialTimestamp(tstamp, buf); else if (timestamp2tm(tstamp, NULL, tm, &fsec, NULL) == 0) EncodeDateTime(tm, fsec, false, 0, NULL, DateStyle, buf, 0); else { errno = PGTYPES_TS_BAD_TIMESTAMP; return NULL; } return pgtypes_strdup(buf); }