-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtzset.c.diff
1107 lines (1083 loc) · 32.6 KB
/
tzset.c.diff
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
*** ./tzset.c.orig Tue Jun 16 23:00:00 1998
--- ./tzset.c Thu Feb 01 23:36:23 2001
***************
*** 1,28 ****
! /***
! *tzset.c - set timezone information and see if we're in daylight time
! *
! * Copyright (c) 1985-1998, Microsoft Corporation. All rights reserved.
! *
! *Purpose:
! * defines _tzset() - set timezone and daylight saving time vars
! *
! *******************************************************************************/
!
! #ifdef _WIN32
!
! #include <cruntime.h>
#include <ctype.h>
- #include <ctime.h>
#include <time.h>
- #include <stdlib.h>
- #include <internal.h>
- #include <mtdll.h>
- #include <windows.h>
- #include <setlocal.h>
- #include <string.h>
- #include <dbgint.h>
-
/*
* Number of milliseconds in one day
--- 1,10 ----
! // tzset.c - adapted from Microsoft C Runtime
! //
! // Time-stamp: <01/02/01 21:31:08 keuchel@lightning>
! #include "celib.h"
#include <ctype.h>
#include <time.h>
/*
* Number of milliseconds in one day
***************
*** 66,339 ****
static int __cdecl _isindst_lk(struct tm *);
!
!
! /***
! *void tzset() - sets timezone information and calc if in daylight time
! *
! *Purpose:
! * Sets the timezone information from the TZ environment variable
! * and then sets _timezone, _daylight, and _tzname. If we're in daylight
! * time is automatically calculated.
! *
! *Entry:
! * None, reads TZ environment variable.
! *
! *Exit:
! * sets _daylight, _timezone, and _tzname global vars, no return value
! *
! *Exceptions:
! *
! *******************************************************************************/
!
!
! #ifdef _MT
! static void __cdecl _tzset_lk(void);
! #else /* _MT */
! #define _tzset_lk _tzset
! #endif /* _MT */
!
! void __cdecl __tzset(void)
{
! static int first_time = 0;
!
! if ( !first_time ) {
! _mlock( _TIME_LOCK );
! if ( !first_time ) {
! _tzset_lk();
! first_time++;
! }
!
! _munlock(_TIME_LOCK );
!
! }
}
!
! #ifdef _MT
! void __cdecl _tzset (
! void
! )
! {
! _mlock( _TIME_LOCK );
!
! _tzset_lk();
!
! _munlock( _TIME_LOCK );
! }
!
!
! static void __cdecl _tzset_lk (
!
! #else /* _MT */
!
! void __cdecl _tzset (
!
! #endif /* _MT */
!
! void
! )
{
! char *TZ;
! int defused;
! int negdiff = 0;
!
! _mlock(_ENV_LOCK);
!
! /*
! * Clear the flag indicated whether GetTimeZoneInformation was used.
! */
! tzapiused = 0;
!
! /*
! * Set year fields of dststart and dstend structures to -1 to ensure
! * they are recomputed as after this
! */
! dststart.yr = dstend.yr = -1;
!
! /*
! * Fetch the value of the TZ environment variable.
! */
! if ( (TZ = _getenv_lk("TZ")) == NULL ) {
!
! /*
! * There is no TZ environment variable, try to use the time zone
! * information from the system.
! */
!
! _munlock(_ENV_LOCK);
!
! if ( GetTimeZoneInformation( &tzinfo ) != 0xFFFFFFFF ) {
! /*
! * Note that the API was used.
! */
! tzapiused = 1;
!
! /*
! * Derive _timezone value from Bias and StandardBias fields.
! */
! _timezone = tzinfo.Bias * 60L;
!
! if ( tzinfo.StandardDate.wMonth != 0 )
! _timezone += (tzinfo.StandardBias * 60L);
!
! /*
! * Check to see if there is a daylight time bias. Since the
! * StandardBias has been added into _timezone, it must be
! * compensated for in the value computed for _dstbias.
! */
! if ( (tzinfo.DaylightDate.wMonth != 0) &&
! (tzinfo.DaylightBias != 0) )
! {
! _daylight = 1;
! _dstbias = (tzinfo.DaylightBias - tzinfo.StandardBias) *
! 60L;
! }
! else {
! _daylight = 0;
!
! /*
! * Set daylight bias to 0 because GetTimeZoneInformation
! * may return TIME_ZONE_ID_DAYLIGHT even though there is
! * no DST (in NT 3.51, just turn off the automatic DST
! * adjust in the control panel)!
! */
! _dstbias = 0;
! }
!
! /*
! * Try to grab the name strings for both the time zone and the
! * daylight zone. Note the wide character strings in tzinfo
! * must be converted to multibyte characters strings. The
! * locale codepage, __lc_codepage, is used for this. Note that
! * if setlocale() with LC_ALL or LC_CTYPE has not been called,
! * then __lc_codepage will be 0 (_CLOCALECP), which is CP_ACP
! * (which means use the host's default ANSI codepage).
! */
! if ( (WideCharToMultiByte( __lc_codepage,
! WC_COMPOSITECHECK |
! WC_SEPCHARS,
! tzinfo.StandardName,
! -1,
! _tzname[0],
! 63,
! NULL,
! &defused ) != 0) &&
! (!defused) )
! _tzname[0][63] = '\0';
! else
! _tzname[0][0] = '\0';
!
! if ( (WideCharToMultiByte( __lc_codepage,
! WC_COMPOSITECHECK |
! WC_SEPCHARS,
! tzinfo.DaylightName,
! -1,
! _tzname[1],
! 63,
! NULL,
! &defused ) != 0) &&
! (!defused) )
! _tzname[1][63] = '\0';
! else
! _tzname[1][0] = '\0';
!
! }
!
! /*
! * Time zone information is unavailable, just return.
! */
! return;
! }
!
!
! if ( (*TZ == '\0') || ((lastTZ != NULL) && (strcmp(TZ, lastTZ) == 0)) )
! {
! /*
! * Either TZ is NULL, pointing to '\0', or is the unchanged
! * from a earlier call (to this function). In any case, there
! * is no work to do, so just return
! */
! _munlock(_ENV_LOCK);
! return;
! }
!
! /*
! * Update lastTZ
! */
! _free_crt(lastTZ);
!
! if ((lastTZ = _malloc_crt(strlen(TZ)+1)) == NULL)
! {
! _munlock(_ENV_LOCK);
! return;
! }
! strcpy(lastTZ, TZ);
!
! _munlock(_ENV_LOCK);
!
! /*
! * Process TZ value and update _tzname, _timezone and _daylight.
! */
!
! strncpy(_tzname[0], TZ, 3);
! _tzname[0][3] = '\0';
!
! /*
! * time difference is of the form:
! *
! * [+|-]hh[:mm[:ss]]
! *
! * check minus sign first.
! */
! if ( *(TZ += 3) == '-' ) {
! negdiff++;
! TZ++;
! }
!
! /*
! * process, then skip over, the hours
! */
! _timezone = atol(TZ) * 3600L;
!
! while ( (*TZ == '+') || ((*TZ >= '0') && (*TZ <= '9')) ) TZ++;
!
! /*
! * check if minutes were specified
! */
! if ( *TZ == ':' ) {
! /*
! * process, then skip over, the minutes
! */
! _timezone += atol(++TZ) * 60L;
! while ( (*TZ >= '0') && (*TZ <= '9') ) TZ++;
!
! /*
! * check if seconds were specified
! */
! if ( *TZ == ':' ) {
! /*
! * process, then skip over, the seconds
! */
! _timezone += atol(++TZ);
! while ( (*TZ >= '0') && (*TZ <= '9') ) TZ++;
! }
! }
!
! if ( negdiff )
! _timezone = -_timezone;
!
! /*
! * finally, check for a DST zone suffix
! */
! if ( _daylight = *TZ ) {
! strncpy(_tzname[1], TZ, 3);
! _tzname[1][3] = '\0';
! }
! else
! *_tzname[1] = '\0';
}
--- 48,262 ----
static int __cdecl _isindst_lk(struct tm *);
! void
! __tzset(void)
{
! static int first_time = 0;
! if ( !first_time ) {
! if ( !first_time ) {
! _tzset();
! first_time++;
! }
! }
}
! void
! _tzset (void)
{
! char *TZ;
! int defused;
! int negdiff = 0;
!
! /*
! * Clear the flag indicated whether GetTimeZoneInformation was used.
! */
! tzapiused = 0;
!
! /*
! * Set year fields of dststart and dstend structures to -1 to ensure
! * they are recomputed as after this
! */
! dststart.yr = dstend.yr = -1;
!
! /*
! * Fetch the value of the TZ environment variable.
! */
! if ( (TZ = xcegetenv("TZ")) == NULL ) {
!
! /*
! * There is no TZ environment variable, try to use the time zone
! * information from the system.
! */
!
! if ( GetTimeZoneInformation( &tzinfo ) != 0xFFFFFFFF ) {
! /*
! * Note that the API was used.
! */
! tzapiused = 1;
!
! /*
! * Derive _timezone value from Bias and StandardBias fields.
! */
! _timezone = tzinfo.Bias * 60L;
!
! if ( tzinfo.StandardDate.wMonth != 0 )
! _timezone += (tzinfo.StandardBias * 60L);
!
! /*
! * Check to see if there is a daylight time bias. Since the
! * StandardBias has been added into _timezone, it must be
! * compensated for in the value computed for _dstbias.
! */
! if ( (tzinfo.DaylightDate.wMonth != 0) &&
! (tzinfo.DaylightBias != 0) )
! {
! _daylight = 1;
! _dstbias = (tzinfo.DaylightBias - tzinfo.StandardBias) *
! 60L;
! }
! else {
! _daylight = 0;
!
! /*
! * Set daylight bias to 0 because GetTimeZoneInformation
! * may return TIME_ZONE_ID_DAYLIGHT even though there is
! * no DST (in NT 3.51, just turn off the automatic DST
! * adjust in the control panel)!
! */
! _dstbias = 0;
! }
!
! /*
! * Try to grab the name strings for both the time zone and the
! * daylight zone. Note the wide character strings in tzinfo
! * must be converted to multibyte characters strings. The
! * locale codepage, __lc_codepage, is used for this. Note that
! * if setlocale() with LC_ALL or LC_CTYPE has not been called,
! * then __lc_codepage will be 0 (_CLOCALECP), which is CP_ACP
! * (which means use the host's default ANSI codepage).
! */
! if ( (WideCharToMultiByte( CP_ACP,
! WC_COMPOSITECHECK |
! WC_SEPCHARS,
! tzinfo.StandardName,
! -1,
! _tzname[0],
! 63,
! NULL,
! &defused ) != 0) &&
! (!defused) )
! _tzname[0][63] = '\0';
! else
! _tzname[0][0] = '\0';
!
! if ( (WideCharToMultiByte( CP_ACP,
! WC_COMPOSITECHECK |
! WC_SEPCHARS,
! tzinfo.DaylightName,
! -1,
! _tzname[1],
! 63,
! NULL,
! &defused ) != 0) &&
! (!defused) )
! _tzname[1][63] = '\0';
! else
! _tzname[1][0] = '\0';
!
! }
!
! /*
! * Time zone information is unavailable, just return.
! */
! return;
! }
!
!
! if ( (*TZ == '\0') || ((lastTZ != NULL) && (strcmp(TZ, lastTZ) == 0)) )
! {
! /*
! * Either TZ is NULL, pointing to '\0', or is the unchanged
! * from a earlier call (to this function). In any case, there
! * is no work to do, so just return
! */
!
! return;
! }
!
! /*
! * Update lastTZ
! */
!
! free(lastTZ);
!
! if ((lastTZ = malloc(strlen(TZ)+1)) == NULL)
! {
! return;
! }
! strcpy(lastTZ, TZ);
!
! /*
! * Process TZ value and update _tzname, _timezone and _daylight.
! */
!
! strncpy(_tzname[0], TZ, 3);
! _tzname[0][3] = '\0';
!
! /*
! * time difference is of the form:
! *
! * [+|-]hh[:mm[:ss]]
! *
! * check minus sign first.
! */
! if ( *(TZ += 3) == '-' ) {
! negdiff++;
! TZ++;
! }
!
! /*
! * process, then skip over, the hours
! */
! _timezone = atol(TZ) * 3600L;
!
! while ( (*TZ == '+') || ((*TZ >= '0') && (*TZ <= '9')) ) TZ++;
!
! /*
! * check if minutes were specified
! */
! if ( *TZ == ':' ) {
! /*
! * process, then skip over, the minutes
! */
! _timezone += atol(++TZ) * 60L;
! while ( (*TZ >= '0') && (*TZ <= '9') ) TZ++;
!
! /*
! * check if seconds were specified
! */
! if ( *TZ == ':' ) {
! /*
! * process, then skip over, the seconds
! */
! _timezone += atol(++TZ);
! while ( (*TZ >= '0') && (*TZ <= '9') ) TZ++;
! }
! }
!
! if ( negdiff )
! _timezone = -_timezone;
!
! /*
! * finally, check for a DST zone suffix
! */
! if ( _daylight = *TZ ) {
! strncpy(_tzname[1], TZ, 3);
! _tzname[1][3] = '\0';
! }
! else
! *_tzname[1] = '\0';
}
***************
*** 510,933 ****
*
*******************************************************************************/
! int __cdecl _isindst (
! struct tm *tb
! )
! #ifdef _MT
{
! int retval;
! _mlock( _TIME_LOCK );
! retval = _isindst_lk( tb );
! _munlock( _TIME_LOCK );
! return retval;
}
-
- static int __cdecl _isindst_lk (
- struct tm *tb
- )
- #endif /* _MT */
- {
- long ms;
-
- if ( _daylight == 0 )
- return 0;
-
- /*
- * Compute (recompute) the transition dates for daylight saving time
- * if necessary.The yr (year) fields of dststart and dstend is
- * compared to the year of interest to determine necessity.
- */
- if ( (tb->tm_year != dststart.yr) || (tb->tm_year != dstend.yr) ) {
- if ( tzapiused ) {
- /*
- * Convert the start of daylight saving time to dststart.
- */
- if ( tzinfo.DaylightDate.wYear == 0 )
- cvtdate( 1,
- 1, /* day-in-month format */
- tb->tm_year,
- tzinfo.DaylightDate.wMonth,
- tzinfo.DaylightDate.wDay,
- tzinfo.DaylightDate.wDayOfWeek,
- 0,
- tzinfo.DaylightDate.wHour,
- tzinfo.DaylightDate.wMinute,
- tzinfo.DaylightDate.wSecond,
- tzinfo.DaylightDate.wMilliseconds );
- else
- cvtdate( 1,
- 0, /* absolute date */
- tb->tm_year,
- tzinfo.DaylightDate.wMonth,
- 0,
- 0,
- tzinfo.DaylightDate.wDay,
- tzinfo.DaylightDate.wHour,
- tzinfo.DaylightDate.wMinute,
- tzinfo.DaylightDate.wSecond,
- tzinfo.DaylightDate.wMilliseconds );
- /*
- * Convert start of standard time to dstend.
- */
- if ( tzinfo.StandardDate.wYear == 0 )
- cvtdate( 0,
- 1, /* day-in-month format */
- tb->tm_year,
- tzinfo.StandardDate.wMonth,
- tzinfo.StandardDate.wDay,
- tzinfo.StandardDate.wDayOfWeek,
- 0,
- tzinfo.StandardDate.wHour,
- tzinfo.StandardDate.wMinute,
- tzinfo.StandardDate.wSecond,
- tzinfo.StandardDate.wMilliseconds );
- else
- cvtdate( 0,
- 0, /* absolute date */
- tb->tm_year,
- tzinfo.StandardDate.wMonth,
- 0,
- 0,
- tzinfo.StandardDate.wDay,
- tzinfo.StandardDate.wHour,
- tzinfo.StandardDate.wMinute,
- tzinfo.StandardDate.wSecond,
- tzinfo.StandardDate.wMilliseconds );
-
- }
- else {
- /*
- * GetTimeZoneInformation API was NOT used, or failed. USA
- * daylight saving time rules are assumed.
- */
- cvtdate( 1,
- 1,
- tb->tm_year,
- 4, /* April */
- 1, /* first... */
- 0, /* ...Sunday */
- 0,
- 2, /* 02:00 (2 AM) */
- 0,
- 0,
- 0 );
-
- cvtdate( 0,
- 1,
- tb->tm_year,
- 10, /* October */
- 5, /* last... */
- 0, /* ...Sunday */
- 0,
- 2, /* 02:00 (2 AM) */
- 0,
- 0,
- 0 );
- }
- }
-
- /*
- * Handle simple cases first.
- */
- if ( dststart.yd < dstend.yd ) {
- /*
- * Northern hemisphere ordering
- */
- if ( (tb->tm_yday < dststart.yd) || (tb->tm_yday > dstend.yd) )
- return 0;
- if ( (tb->tm_yday > dststart.yd) && (tb->tm_yday < dstend.yd) )
- return 1;
- }
- else {
- /*
- * Southern hemisphere ordering
- */
- if ( (tb->tm_yday < dstend.yd) || (tb->tm_yday > dststart.yd) )
- return 1;
- if ( (tb->tm_yday > dstend.yd) && (tb->tm_yday < dststart.yd) )
- return 0;
- }
-
- ms = 1000L * (tb->tm_sec + 60L * tb->tm_min + 3600L * tb->tm_hour);
-
- if ( tb->tm_yday == dststart.yd ) {
- if ( ms >= dststart.ms )
- return 1;
- else
- return 0;
- }
- else {
- /*
- * tb->tm_yday == dstend.yd
- */
- if ( ms < dstend.ms )
- return 1;
- else
- return 0;
- }
-
- }
-
-
-
- #else /* _WIN32 */
-
- #if defined (_M_MPPC) || defined (_M_M68K)
-
-
- #include <cruntime.h>
- #include <ctype.h>
- #include <ctime.h>
- #include <time.h>
- #include <stdlib.h>
- #include <internal.h>
- #include <string.h>
- #include <macos\script.h>
- #include <macos\osutils.h>
-
- /***
- *void tzset() - sets timezone information and calc if in daylight time
- *
- *Purpose:
- * Sets the timezone information from the TZ environment variable
- * and then sets _timezone, _daylight, and _tzname. If we're in daylight
- * time is automatically calculated.
- *
- *Entry:
- * None, reads TZ environment variable.
- *
- *Exit:
- * sets _daylight, _timezone, and _tzname global vars, no return value
- *
- *Exceptions:
- *
- *******************************************************************************/
-
- void __cdecl _tzset (
- void
- )
- {
- REG1 char *TZ;
- char *lastTZ=NULL;
- MachineLocation ml;
- long gmtDelta;
- REG2 int negdiff = 0;
-
- /*
- * Fetch the value of the TZ environment variable. If there is no TZ
- * environment variable, or if it is trivial, then the timezone
- * information will be taken from the OS.
- */
-
- if ( (TZ = getenv("TZ")) && (*TZ) ) {
- /*
- * TZ environment variable exists and is non-trivial. See if
- * it is unchanged from a previous _tzset call.
- */
- if ( (lastTZ == NULL) || (strcmp(TZ, lastTZ) != 0) ) {
- /*
- * TZ has changed, or there has been no prior _tzset call.
- * Update lastTZ value.
- */
- free(lastTZ);
- lastTZ = _strdup(TZ);
- }
- else {
- /*
- * Timezone environment variable hasn't changed since the
- * last _tzset call, just return.
- */
- return;
-
- }
- }
- else {
- /*
- * The TZ environment variable either does not exist, or is
- * trivial. Therefore, timezone information will be obtained
- * from the OS.
- */
- if ( lastTZ != NULL ) {
- free(lastTZ);
- lastTZ = NULL;
- }
- ReadLocation(&ml);
- //get gmtDelta from machinelocation in RAM
- gmtDelta = ml.u.gmtDelta & 0x00ffffff;
-
- if ((gmtDelta >> 23) & 1) //need to sign extend
- gmtDelta = gmtDelta | 0xff000000;
-
- //set timezone and daylight
- _timezone = - gmtDelta;
- _daylight = (ml.u.dlsDelta ? 1 : 0);
- *_tzname[0] = '\0';
- *_tzname[1] = '\0';
- return;
- }
-
- strncpy(_tzname[0], TZ, 3);
-
- /*
- * time difference is of the form:
- *
- * [+|-]hh[:mm[:ss]]
- *
- * check minus sign first.
- */
- if ( *(TZ += 3) == '-' ) {
- negdiff++;
- TZ++;
- }
-
- /*
- * process, then skip over, the hours
- */
- _timezone = atol(TZ) * 3600L;
-
- while ( (*TZ == '+') || ((*TZ >= '0') && (*TZ <= '9')) ) TZ++;
-
- /*
- * check if minutes were specified
- */
- if ( *TZ == ':' ) {
- /*
- * process, then skip over, the minutes
- */
- _timezone += atol(++TZ) * 60L;
- while ( (*TZ >= '0') && (*TZ <= '9') ) TZ++;
-
- /*
- * check if seconds were specified
- */
- if ( *TZ == ':' ) {
- /*
- * process, then skip over, the seconds
- */
- _timezone += atol(++TZ);
- while ( (*TZ >= '0') && (*TZ <= '9') ) TZ++;
- }
- }
- if ( negdiff )
- _timezone = -_timezone;
-
- /*
- * finally, check for a DST zone suffix
- */
- if (*TZ)
- strncpy(_tzname[1], TZ, 3);
- else
- *_tzname[1] = '\0';
- _daylight = *_tzname[1] != '\0';
- }
-
- /*
- * _isindst - Tells whether Xenix-type time value falls under DST
- *
- * This is the rule for years before 1987:
- * a time is in DST iff it is on or after 02:00:00 on the last Sunday
- * in April and before 01:00:00 on the last Sunday in October.
- * This is the rule for years starting with 1987:
- * a time is in DST iff it is on or after 02:00:00 on the first Sunday
- * in April and before 01:00:00 on the last Sunday in October.
- *
- * ENTRY tb - 'time' structure holding broken-down time value
- *
- * RETURN 1 if time represented is in DST, else 0
- */
-
- int __cdecl _isindst (
- REG1 struct tm *tb
- )
- {
- int mdays;
- REG2 int yr;
- int lastsun;
-
- /* If the month is before April or after October, then we know
- * immediately it can't be DST. */
-
- if (tb->tm_mon < 3 || tb->tm_mon > 9)
- return(0);
-
- /* If the month is after April and before October then we know
- * immediately it must be DST. */
-
- if (tb->tm_mon > 3 && tb->tm_mon < 9)
- return(1);
- /*
- * Now for the hard part. Month is April or October; see if date
- * falls between appropriate Sundays.
- */
-
- /*
- * The objective for years before 1987 (after 1986) is to determine
- * if the day is on or after 2:00 am on the last (first) Sunday in
- * April, or before 1:00 am on the last Sunday in October.
- *
- * We know the year-day (0..365) of the current time structure. We must
- * determine the year-day of the last (first) Sunday in this month,
- * April or October, and then do the comparison.
- *
- * To determine the year-day of the last Sunday, we do the following:
- * 1. Get the year-day of the last day of the current month (Apr
- * or Oct)
- * 2. Determine the week-day number of #1,
- * which is defined as 0 = Sun, 1 = Mon, ... 6 = Sat
- * 3. Subtract #2 from #1
- *
- * To determine the year-day of the first Sunday, we do the following:
- * 1. Get the year-day of the 7th day of the current month (April)
- * 2. Determine the week-day number of #1,
- * which is defined as 0 = Sun, 1 = Mon, ... 6 = Sat
- * 3. Subtract #2 from #1
- */
-
- yr = tb->tm_year + 1900; /* To see if this is a leap-year */
-
- /* First we get #1. The year-days for each month are stored in _days[]
- * they're all off by -1 */
-
- if (yr > 1986 && tb->tm_mon == 3)
- mdays = 7 + _days[tb->tm_mon];
- else
- mdays = _days[tb->tm_mon+1];
-
- /* if this is a leap-year, add an extra day */
- if (!(yr & 3))
- mdays++;
-
- /* mdays now has #1 */
-
- yr = tb->tm_year - 70;
-
- /* Now get #2. We know the week-day number of the beginning of the
- * epoch, Jan. 1, 1970, which is defined as the constant _BASE_DOW. We
- * then add the number of days that have passed from _BASE_DOW to the day
- * of #2
- * mdays + 365 * yr
- * correct for the leap years which intervened
- * + (yr + 1)/ 4
- * and take the result mod 7, except that 0 must be mapped to 7.
- * This is #2, which we then subtract from #1, mdays
- */
-
- lastsun = mdays - ((mdays + 365*yr + ((yr+1)/4) + _BASE_DOW) % 7);
-
- /* Now we know 1 and 3; we're golden: */
-
- return (tb->tm_mon==3
- ? (tb->tm_yday > lastsun ||
- (tb->tm_yday == lastsun && tb->tm_hour >= 2))
- : (tb->tm_yday < lastsun ||
- (tb->tm_yday == lastsun && tb->tm_hour < 1)));
- }
-
-
-
-
- #endif /* defined (_M_MPPC) || defined (_M_M68K) */
-
- #endif /* _WIN32 */
--- 433,577 ----
*
*******************************************************************************/
! int
! _isindst (struct tm *tb)
{
! long ms;
! if ( _daylight == 0 )
! return 0;
! /*
! * Compute (recompute) the transition dates for daylight saving time
! * if necessary.The yr (year) fields of dststart and dstend is
! * compared to the year of interest to determine necessity.
! */
! if ( (tb->tm_year != dststart.yr) || (tb->tm_year != dstend.yr) ) {
! if ( tzapiused ) {
! /*
! * Convert the start of daylight saving time to dststart.
! */
! if ( tzinfo.DaylightDate.wYear == 0 )
! cvtdate( 1,
! 1, /* day-in-month format */
! tb->tm_year,
! tzinfo.DaylightDate.wMonth,
! tzinfo.DaylightDate.wDay,
! tzinfo.DaylightDate.wDayOfWeek,
! 0,
! tzinfo.DaylightDate.wHour,
! tzinfo.DaylightDate.wMinute,
! tzinfo.DaylightDate.wSecond,
! tzinfo.DaylightDate.wMilliseconds );
! else
! cvtdate( 1,
! 0, /* absolute date */
! tb->tm_year,
! tzinfo.DaylightDate.wMonth,