Line data Source code
1 : /*
2 : * linux/fs/isofs/util.c
3 : */
4 :
5 : #include "isofs.h"
6 :
7 : /*
8 : * We have to convert from a MM/DD/YY format to the Unix ctime format.
9 : * We have to take into account leap years and all of that good stuff.
10 : * Unfortunately, the kernel does not have the information on hand to
11 : * take into account daylight savings time, but it shouldn't matter.
12 : * The time stored should be localtime (with or without DST in effect),
13 : * and the timezone offset should hold the offset required to get back
14 : * to GMT. Thus we should always be correct.
15 : */
16 :
17 : int iso_date(char * p, int flag)
18 : {
19 176 : int year, month, day, hour, minute, second, tz;
20 176 : int crtime, days, i;
21 176 :
22 352 : year = p[0] - 70;
23 352 : month = p[1];
24 352 : day = p[2];
25 352 : hour = p[3];
26 352 : minute = p[4];
27 352 : second = p[5];
28 704 : if (flag == 0) tz = p[6]; /* High sierra has no time zone */
29 352 : else tz = 0;
30 :
31 352 : if (year < 0) {
32 176 : crtime = 0;
33 : } else {
34 2112 : int monlen[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
35 :
36 176 : days = year * 365;
37 352 : if (year > 2)
38 176 : days += (year+1) / 4;
39 880 : for (i = 1; i < month; i++)
40 528 : days += monlen[i-1];
41 880 : if (((year+2) % 4) == 0 && month > 2)
42 176 : days++;
43 176 : days += day - 1;
44 176 : crtime = ((((days * 24) + hour) * 60 + minute) * 60)
45 : + second;
46 :
47 : /* sign extend */
48 352 : if (tz & 0x80)
49 176 : tz |= (-1 << 8);
50 :
51 : /*
52 : * The timezone offset is unreliable on some disks,
53 : * so we make a sanity check. In no case is it ever
54 : * more than 13 hours from GMT, which is 52*15min.
55 : * The time is always stored in localtime with the
56 : * timezone offset being what get added to GMT to
57 : * get to localtime. Thus we need to subtract the offset
58 : * to get to true GMT, which is what we store the time
59 : * as internally. On the local system, the user may set
60 : * their timezone any way they wish, of course, so GMT
61 : * gets converted back to localtime on the receiving
62 : * system.
63 : *
64 : * NOTE: mkisofs in versions prior to mkisofs-1.10 had
65 : * the sign wrong on the timezone offset. This has now
66 : * been corrected there too, but if you are getting screwy
67 : * results this may be the explanation. If enough people
68 : * complain, a user configuration option could be added
69 : * to add the timezone offset in with the wrong sign
70 : * for 'compatibility' with older discs, but I cannot see how
71 : * it will matter that much.
72 : *
73 : * Thanks to kuhlmav@elec.canterbury.ac.nz (Volker Kuhlmann)
74 : * for pointing out the sign error.
75 : */
76 352 : if (-52 <= tz && tz <= 52)
77 176 : crtime -= tz * 15 * 60;
78 : }
79 352 : return crtime;
80 : }
|