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
|
#include <time.h>
#include "time_defs.h"
void num2str(char *c,int i) /*EXTRACT_INCL*/{c[0]=i/10+'0'; c[1]=i%10+'0';}
unsigned int nv_ctime(char *p, time_t now, int len) /*EXTRACT_INCL*/{
char days[] = "SunMonTueWedThuFriSat";
char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
unsigned long day, mon, year, tod;
now += get_tz(&now, 1);
tod = (unsigned long)(now) % 86400;
day = (unsigned long)(now) / 86400;
byte_set(p, len, ' ');
str_add(p, days +3*((day+4) % 7), 3);
year = 4*day + 2;
year /= 1461;
day += 671;
day %= 1461; /* day 0 is march 1, 1972 */
if (day == 1460) { day = 365; }
else { day %= 365; }
day *= 10;
mon = (day + 5) / 306;
day = day + 5 - 306 * mon;
day /= 10;
if (mon >= 10) mon -= 10;
else mon += 2; /* day 0,1,30, mon 0..11, year 1970=0,1,2 */
/* 4 8 11 14 17 20 */
/* "Fri Jan 7 21:08:30 2005\n" */
str_add(p+4, months+3*mon, 3);
num2str(p+8, day+1); if (p[8]=='0') p[8]=' ';
num2str(p+17, tod%60); tod /= 60;
num2str(p+11, tod/60);
num2str(p+14, tod%60);
p[20 + fmt_ulong(p+20, 1970 + year)] = '\n';
p[13] = ':'; p[16] = ':';
return len;
}
|