-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht10_ciTimes.c
99 lines (65 loc) · 1.6 KB
/
t10_ciTimes.c
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "op.h"
#include <time.h>
#include <sys/time.h>
static time_t lmid = 0;
void setmid()
{
struct tm loc;
time_t lt;
lt = time(NULL);
(void) localtime_r(<, &loc);
loc.tm_sec = 0;
loc.tm_min = 0;
loc.tm_hour = 0;
lmid = mktime(&loc);
}
// Number of milliseconds since midnight (local time)
// No error return
// gettimeofday may be only high-resolution time for cygwin
_SUB int t10_CALLI_MSTIME(PCTX *ctx)
{
struct timeval tp;
struct timezone tzp;
BIGV rval;
(void) gettimeofday(&tp,&tzp);
if (tp.tv_sec - lmid > 86400) setmid(); // Set midnight if needed
rval = tp.tv_sec - lmid;
rval *= 1000;
rval += tp.tv_usec / 1000;
WRITEMEM(jctx, ctx->AC, rval);
CHKERROR(jctx);
return(OK_EXIT);
}
// Return date
// code = 31[12(year-1964)+(month-1)]+(day-1)
// day = mod(code,31)+1
// month = mod(code/31,12)+1
// year = (code/372)+1964
// No error return
_SUB int t10_CALLI_DATE(PCTX *ctx)
{
struct tm intm;
time_t it;
int rtim;
it = time(NULL);
(void) localtime_r(&it, &intm);
rtim = (31*((12*(intm.tm_year-64)) + (intm.tm_mon))) + (intm.tm_mday-1);
WRITEMEM(jctx, ctx->AC, rtim);
CHKERROR(jctx);
return(OK_EXIT);
}
// Return time since midnight in jiffies (1/60 sec)
_SUB int t10_CALLI_TIMER(PCTX *ctx)
{
struct timeval tp;
struct timezone tzp;
BIGV rval;
(void) gettimeofday(&tp,&tzp);
if (tp.tv_sec - lmid > 86400) setmid(); // Set midnight if needed
rval = tp.tv_sec - lmid;
rval *= 60;
rval += tp.tv_usec / 16667;
WRITEMEM(jctx, ctx->AC, rval);
CHKERROR(jctx);
return(OK_EXIT);
}