File: Date.c

package info (click to toggle)
mlton 20100608-5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 36,624 kB
  • sloc: ansic: 18,441; lisp: 2,879; makefile: 1,572; sh: 1,326; pascal: 256; asm: 97
file content (53 lines) | stat: -rw-r--r-- 1,866 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "platform.h"

static struct tm Date_tmIn;
static struct tm *Date_tmOut;

C_Int_t Date_Tm_getHour(void) { return Date_tmOut->tm_hour; }
C_Int_t Date_Tm_getIsDst(void) { return Date_tmOut->tm_isdst; }
C_Int_t Date_Tm_getMDay(void) { return Date_tmOut->tm_mday; }
C_Int_t Date_Tm_getMin(void) { return Date_tmOut->tm_min; }
C_Int_t Date_Tm_getMon(void) { return Date_tmOut->tm_mon; }
C_Int_t Date_Tm_getSec(void) { return Date_tmOut->tm_sec; }
C_Int_t Date_Tm_getWDay(void) { return Date_tmOut->tm_wday; }
C_Int_t Date_Tm_getYDay(void) { return Date_tmOut->tm_yday; }
C_Int_t Date_Tm_getYear(void) { return Date_tmOut->tm_year; }

void Date_Tm_setHour(C_Int_t x) { Date_tmIn.tm_hour = x; }
void Date_Tm_setIsDst(C_Int_t x) { Date_tmIn.tm_isdst = x; }
void Date_Tm_setMDay(C_Int_t x) { Date_tmIn.tm_mday = x; }
void Date_Tm_setMin(C_Int_t x) { Date_tmIn.tm_min = x; }
void Date_Tm_setMon(C_Int_t x) { Date_tmIn.tm_mon = x; }
void Date_Tm_setSec(C_Int_t x) { Date_tmIn.tm_sec = x; }
void Date_Tm_setWDay(C_Int_t x) { Date_tmIn.tm_wday = x; }
void Date_Tm_setYDay(C_Int_t x) { Date_tmIn.tm_yday = x; }
void Date_Tm_setYear(C_Int_t x) { Date_tmIn.tm_year = x; }

C_Errno_t(C_Int_t) Date_gmTime(Ref(C_Time_t) p) {
  Date_tmOut = gmtime((time_t*)p);
  if (Date_tmOut == NULL) return -1;
  return 0;
}

/* The idea for Date_localOffset comes from KitV3 src/Runtime/Time.c */
C_Double_t Date_localOffset(void) {
  time_t t1, t2;

  t1 = time(NULL);
  t2 = mktime(gmtime(&t1));
  return difftime(t2, t1);
}

C_Errno_t(C_Int_t) Date_localTime(Ref(C_Time_t) p) {
  Date_tmOut = localtime((time_t*)p);
  if (Date_tmOut == NULL) return -1;
  return 0;
}

C_Errno_t(C_Time_t) Date_mkTime(void) {
  return mktime(&Date_tmIn);
}

C_Size_t Date_strfTime(Array(Char8_t) buf, C_Size_t n, NullString8_t fmt) {
  return strftime((char*)(buf), n, (const char*)(fmt), &Date_tmIn);
}