-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdate822fmt.c
63 lines (56 loc) · 1.77 KB
/
date822fmt.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
#include <time.h>
#include "datetime.h"
#include "fmt.h"
#include "date822fmt.h"
static char *montab[12] = {
"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
};
unsigned int date822fmt(s,dt)
char *s;
struct datetime *dt;
{
unsigned int i;
unsigned int len;
time_t now;
datetime_sec utc;
datetime_sec local;
struct tm *tm;
struct datetime new_dt;
int minutes;
utc = datetime_untai(dt);
now = (time_t)utc;
tm = localtime(&now);
new_dt.year = tm->tm_year;
new_dt.mon = tm->tm_mon;
new_dt.mday = tm->tm_mday;
new_dt.hour = tm->tm_hour;
new_dt.min = tm->tm_min;
new_dt.sec = tm->tm_sec;
local = datetime_untai(&new_dt);
len = 0;
i = fmt_uint(s,new_dt.mday); len += i; if (s) s += i;
i = fmt_str(s," "); len += i; if (s) s += i;
i = fmt_str(s,montab[new_dt.mon]); len += i; if (s) s += i;
i = fmt_str(s," "); len += i; if (s) s += i;
i = fmt_uint(s,new_dt.year + 1900); len += i; if (s) s += i;
i = fmt_str(s," "); len += i; if (s) s += i;
i = fmt_uint0(s,new_dt.hour,2); len += i; if (s) s += i;
i = fmt_str(s,":"); len += i; if (s) s += i;
i = fmt_uint0(s,new_dt.min,2); len += i; if (s) s += i;
i = fmt_str(s,":"); len += i; if (s) s += i;
i = fmt_uint0(s,new_dt.sec,2); len += i; if (s) s += i;
if (local < utc) {
minutes = (utc - local + 30) / 60;
i = fmt_str(s," -"); len += i; if (s) s += i;
i = fmt_uint0(s,minutes / 60,2); len += i; if (s) s += i;
i = fmt_uint0(s,minutes % 60,2); len += i; if (s) s += i;
}
else {
minutes = (local - utc + 30) / 60;
i = fmt_str(s," +"); len += i; if (s) s += i;
i = fmt_uint0(s,minutes / 60,2); len += i; if (s) s += i;
i = fmt_uint0(s,minutes % 60,2); len += i; if (s) s += i;
}
i = fmt_str(s,"\n"); len += i; if (s) s += i;
return len;
}