-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathESBDates.pas
4971 lines (4289 loc) · 124 KB
/
ESBDates.pas
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
unit ESBDates;
{: ESB Date/Time Routines Collection v3.0.1 for Borland Delphi.
Date/Time Routines to enhance your 32-bit Delphi
Programming. <p>
Copyright (c) 1999-2001 ESB Consultancy <p>
Recommend checking out (included): <p>
http://www.tondering.dk/claus/calendar.html<p>
FREQUENTLY ASKED QUESTIONS ABOUT CALENDARS<p>
Some of our algorithms are based on info from the above. <p>
ISO-8601 Document (not included) can be obtained as a PDF file from:<p>
http://www.iso.ch/markete/8601.pdf <p>
RFC822 Text File (not included) can be obtained from:<p>
http://info.internet.isi.edu/in-notes/rfc/files/rfc822.txt <p>
=================================================== <p>
These routines are used by ESB Consultancy within the
development of their Customised Application. <p>
ESB Consultancy retains full copyright. <p>
ESB Consultancy grants users of this code royalty free rights
to do with this code as they wish. <p>
ESB Consultancy makes no guarantees nor excepts any liabilities
due to the use of these routines. <p>
We do ask that if this code helps you in you development
that you send as an email mailto:info@esbconsult.com.au or even
a local postcard. It would also be nice if you gave us a
mention in your About Box, Help File or Documentation. <p>
ESB Consultancy Home Page: http://www.esbconsult.com.au/<p>
Mail Address: PO Box 2259, Boulder, WA 6449 AUSTRALIA <p>
For Date and Time Edit Components check out our ESB Professional
Computation Suite (ESBPCS) - trial versions available now.
Check out the website at http://www.esbconsult.com.au/esbpcs2/<p>
History: <p>
v3.0.1 7-Sep-2001<p>
- Add GpTimeZone v1.21<p>
- Improved D2 support<p>
<p>
v3.0.0 6-Sep-2001<p>
- Testing is only done for Delphi 4 and above from here on in.<p>
- Delphi 6 Support added.<p>
- Heaps more constants added.<p>
- Optimised Encoding and Decoding of Dates.<p>
- ResourceStrings now used.<p>
- Date formatted as an MS Access Style Comparison Added.<p>
- Date formatted as an ANSI SQL Style Comparison Added.<p>
- Heaps of Date and Time Conversion Routines added.<p>
- Added an Enhanced Str2Date Conversion.<p>
- Add GpTimeZone v1.2<p>
<p>
v2.2.0 3-Feb-2001<p>
- Fixed bug with IsAugustNow<p>
<p>
v2.1.0 6-Oct-2000<p>
- Add GpTimeZone v1.1b<p>
- Add Calendar FAQ v2.3<p>
- Added Calendar Weeks Apart<p>
- Added Calendar Months Apart<p>
- Added IsValidLongMonth & IsValidShortMonth Routines<p>
- Added IsValidLongDOW & IsValidShortDOW Routines<p>
- Added IsFirstDayOfMonth, IsLastDayofMonth Comparisons<p>
- Added IsFirstDayOfYear, IsLastDayofYear Comparisons<p>
- Added ISODateTime2DateTime as suggested by Wolfgang Werner.<p>
- Fixed TimeApartInSecs - thanks to Mark Lussier.<p>
<p>
v2.0.0 17-Feb-2000<p>
- Add GpTimeZone v1.1<p>
- Added TFileTime / TDateTime Conversions donated by J Peter Mugaas<p>
- Added DateTimeToLargeInteger donated by Damien Racca<p>
- Added DT Constants<p>
- Added TimeApartInXXX routines<p>
- Added SameDate, SameTime, SameDateTime<p>
- DOW2Int & Month2Int relpaced by DayName2DOW & MonthName2Month<p>
- Date to Short Month, Long Month, Short DOW, Long DOW Routines added<p>
- Added GMTNow, GMTDate, GMTTime to return the current Date/Time info at
GMT/UTC.<p>
- Redesigned Help<p>
v1.8.2 5-Nov-99<p>
- Calender21.txt included<p>
- URL's updated<p>
v1.8.1 24-Oct-99<p>
- Add GpTimeZone v1.0.1<p>
- GpTimeZone Demo Project now works with Delphi 3<p>
v1.8 18-Oct-99<p>
- Removed Daylight Savings Routines due to bugs and included new unit
GpTimeZone from Primoz Gabrijelcic. Many thanks also to Chris Means
for his identification of problems with our routine.<p>
v1.7 6-September-99<p>
- D5 Compatibility added<p>
- Updated Str2Time<p>
- Redesigned Str2Date - previous version didn't work with all DateFormats<p>
- Added Elapsing Time donated by Laurent PIERRE<p>
v1.6 1-August-99<p>
- Now over 175 Routines<p>
- Str2Date now allows year to be omitted - assumes current year<p>
- Str2Date now allows you to decide how 2 Digit Years are to be processed<p>
- Str2HistoricDate assumes 2 Digit Years are this year or earlier<p>
- Str2CutoffDate uses a Cutoff Date to control how 2 Digit Years are processed<p>
- Date2Str more tolerant of returning an empty string
- Fixed Problem with AddMonths with Negative Months
- Fixed bug in GetFirstSundayOfYear
- Age in Months & Weeks Routines donated by David Gobbett - aimed at Hospital Application
- Added Various ISO-8601 Compliant Week and Formatting routines - thanks to Niklas Astrom
- Links to ISO-8601 and RFC-822 added
v1.5 12-July-99<p>
- Now over 150 Routines<p>
- Added Subtraction routines for completeness - suggested by Wolfgang Wendefeuer<p>
- AgeAtDate and AgeNow Routines added<p>
- Fixed a number of mistakes in the comments<p>
- Conversion of English Day of Week Description to Integer<p>
- Conversion of English Month Description to Integer<p>
- WeeksApart (Integer) and ExactWeeksApart (Float) added<p>
- Added GetFirstSundayOfYear<p>
- Added Week Number processing<p>
v1.4.1 18-June-99<p>
- Fixed Bug in ConvertRFC822Times<p>
v1.4 21-May-99<p>
- Now have over 125 Routines!<p>
- Added AddDays (though this is simple Addition) for completion<p>
- Added Heaps of new Date/Time Arithmetic Routines.
Many suggested by John Atchison<p>
- Added Heaps of Boolean Routines like IsJanuary, IsMonday, etc.
Many suggested by John Atchison<p>
- Added Seconds (Floating) to a string of days, hours, minutes, seconds.
Routine donated by: Marcos Guzmán Montañez<p>
v1.3 27-Apr-99<p>
- Added TimeZone constants missing from D3 (but in D4 Windows.pas)<p>
- Added StartofWeek which returns the Start of the week a date is in, i.e. the Sunday<p>
- Added Routine to set Local Time Bias - see warnings below<p>
- Added Routine to return Daylight Savings Info<p>
- Added Routine to return set Daylight Savings Info - see warnings below<p>
- Added Routines to return current Details - ThisYear, ThisMonth, ThisDay,
ThisHr, ThisMin, ThisSec, ThisMSec<p>
v1.2 19-Apr-1999<p>
- Added RFC822 Time Zone Routines <p>
- Fixed problem with Str2Ext <p>
v 1.1 6-Apr-1999<p>
- Added Better IsLeapYear<p>
- Added GetFirstDayOfMonth & GetLastDayOfMonth<p>
- Added Constants for Tropical Year and Synodic Month<p>
- Added Calculation of GoldenNumber and Epact for given year<p>
- Added GetGoodFriday and GetEasterSunday for given year<p>
- Added GMTStr2Value<p>
- Added GetLocalTZBias - which allows for Daylight Savings settings<p>
- Added GetLocalTime - turns GMT into Local via Regional Settings<p>
- All Local Time Zone routines handle Standard/Daylight Biases<p>
- Added ConvertGMTStrTimes to convert between two GMT related Date/Times<p>
v 1.0 6-Mar-1999 Intial Release <p>
People who have helped out with ESBDates via good suggestions and/or
code snippets:<P>
Scott Kane<p>
Peter Ogden<p>
Dr John Stockton<p>
John Atchison<p>
Marcos Guzmán Montañez<p>
Wolfgang Wendefeuer<p>
Gary Mugford<p>
David Gobbett<p>
Niklas Astrom<p>
Laurent PIERRE<p>
Chris Means<p>
Primoz Gabrijelcic<p>
J. Peter Mugaas<p>
Damien Racca<p>
Wolfgang Werner<p>
Mark Lussier<p>
Ken Otto<p>
Joel Joly
}
interface
{.$Define UseESBRoutines} // Uncomment if you have ESB Routines
{$IFDEF VER120}
{$DEFINE D4Plus}
{$ENDIF}
{$IFDEF VER125}
{$DEFINE D4Plus}
{$ENDIF}
{$IFDEF VER130}
{$DEFINE D4Plus}
{$ENDIF}
{$IFDEF VER140}
{$DEFINE D4Plus}
{$ENDIF}
uses
Windows;
{$IFNDEF D4PLUS}
const
TIME_ZONE_ID_STANDARD = 1;
TIME_ZONE_ID_DAYLIGHT = 2;
{$ENDIF}
{$IFDEF VER90}
type
LongInt = Integer;
{$ENDIF VER90}
// Date/Time Related Messages
ResourceString
rsInvalidDate = 'Invalid Date';
rsInvalidTime = 'Invalid Time';
rsInvalidDateTime = 'Invalid Date/Time';
const
//: Fraction of a TDateTime that represents One Hour.
OneDTHour = 1 / 24;
//: Fraction of a TDateTime that represents One Minute.
OneDTMinute = 1 / (24 * 60);
//: Fraction of a TDateTime that represents One Second.
OneDTSecond = 1 / (24 * 60 * 60);
//: Fraction of a TDateTime that represents One Millisecond.
OneDTMillisecond = 1 / (24 * 60 * 60 * 1000);
const
//: Seconds Per Minute
SecsPerMin = 60;
//: Minutes Per Second
MinsPerSec = 1 / 60;
//: Minutes Per Hour
MinsPerHr = 60;
//: Hours Per Minute
HrsPerMin = 1 / 60;
//: Seconds Per Hour
SecsPerHr = 3600;
//: Hours Per Per Second
HrsPerSec = 1 / 3600;
//: Hours Per Day
HrsPerDay = 24;
//: Days Per Hour
DaysPerHr = 1 / 24;
//: Minutes Per Day
MinsPerDay = 24 * 60;
//: Days Per Minute
DaysPerMin = 1 / (24 * 60);
//: Seconds Per Day
SecsPerDay = 24 * 3600;
//: Days Per Second
DaysPerSec = 1 / (24 * 3600);
//: Days Per Week
DaysPerWeek = 7;
//: Weeks Per Day
WeeksPerDay = 1 / 7;
//: Days Per Fortnight
DaysPerFortnight = 14;
//: Fortnights Per Day
FortnightsPerDay = 1 / 14;
const
{: Time it takes, in days, for the Earth to go from a point in
its rotation and return to that point, i.e. a revolution.
This amount changes (gets smaller) as time progresses.
In 2100 it will be 365.242184 }
DaysPerTropicalYear = 365.24219;
// Days per Gregorian Year
DaysPerGregorianYear = 365.2425;
// Days per Julian Year
DaysPerJulianYear = 365.25;
{: Time it takes, in days, from one New Moon to the next.
This amount change (gets larger) as time progresses.
in 2100 it will be 29.5305891 }
DaysPerSynodicMonth = 29.53059;
type
{: Different ways in which 1 & 2 Digit Years are handled in Str2Date
and in the Date Edit Components.
@enum edyNone Nothing is done, left to Delphi to handle.
@enum edyCutOff the <See Var=ESB2DigitCutOff> is used to decide
which century the date lies in. If 1900 + Yr is less than
ESB2DigitCutOff then it is assumed that 2000 + Yr is wanted,
otherwise 1900 + Yr is used.
@enum edyHistoric assumes that the yr is this year or earlier. }
TESB2DigitYr = (edyNone, edyCutOff, edyHistoric);
var
{: Different ways in which 1 & 2 Digit Years are handled in Str2Date
and in the Date Edit Components.
edyNone - Nothing is done, left to Delphi to handle. <p>
edyCutOff - the <See Var=ESB2DigitCutOff> is used to decide
which century the date lies in. If 1900 + Yr is less than
ESB2DigitCutOff then it is assumed that 2000 + Yr is wanted,
otherwise 1900 + Yr is used.<p>
edyHistoric - assumes that the yr is this year or earlier. }
ESB2DigitYr: TESB2DigitYr = edyCutOff;
{: If <See Var=ESB2DigitYr> = edyCutOff - then ESB2DigitCutOff is used
to decide which century the date lies in. If 1900 + Yr less than
ESB2DigitCutOff then it is assumed that 2000 + Yr is wanted,
otherwise 1900 + Yr is used. }
ESB2DigitCutOff: Word = 1920;
//: English Days of Week - used for DOW2Int
const
DayOfWeekStrings: array [1..7] of String = ('SUNDAY', 'MONDAY', 'TUESDAY',
'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY');
//: English Calendar Months - used for Month2Int
const
MonthStrings: array [1..12] of String = ('JANUARY', 'FEBRUARY', 'MARCH',
'APRIL','MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER',
'NOVEMBER', 'DECEMBER');
{--- Current Date ---}
{: A Speed Optimised Routine to get the Current Date. Time Portion is Zero.
@cat DTMath
}
function OptDate: TDateTime;
{--- Conversions ---}
{: A Speed Optimised DecodeDate developed by Ken Otto that is many times faster
than the once included in SysUtils. If you need Words rather than Integers
use the slightly slower OptDecodeDateW.
@cat DTConv
}
procedure OptDecodeDateI (const DT: TDateTime; out Year, Month, Day: Integer);
{: A Speed Optimised DecodeDate developed by Ken Otto that is many times faster
than the once included in SysUtils. If you want even faster results and
are happy to use Integers than use the slightly slower OptDecodeDateI.
@cat DTConv
}
procedure OptDecodeDateW (const DT: TDateTime; out Year, Month, Day: Word);
{: A Speed Optimised EncodeDate developed by Ken Otto that is many times faster
than the once included in SysUtils, and includes Exception Handling. If you
need Words rather than Integers use the slightly slower OptEncodeDateW.
@cat DTConv
}
function OptEncodeDateI (Year, Month, Day: Integer): TDateTime;
{: A Speed Optimised EncodeDate developed by Ken Otto that is many times faster
than the once included in SysUtils, and includes Exception Handling. If you
want even faster results and are happy to use Integers than use the
slightly slower OptEncodeDateI.
@cat DTConv
}
function OptEncodeDateW (Year, Month, Day: Word): TDateTime;
{: A Speed Optimised Routine for getting the Year portion of a Date based on
Routine by Ken Otto that is many times faster than using DecodeDate in
SysUtils.
@cat DTConv
}
function OptDate2Year (const DT: TDateTime) : Word;
{: A Speed Optimised Routine for getting the Month portion of a Date based on
Routine by Ken Otto that is many times faster than using DecodeDate in
SysUtils.
@cat DTConv
}
function OptDate2Month (const DT: TDateTime) : Word;
{: A Speed Optimised Routine for getting the Day portion of a Date based on
Routine by Ken Otto that is many times faster than using DecodeDate in
SysUtils.
@cat DTConv
}
function OptDate2Day (const DT: TDateTime) : Word;
{: Returns the current Year - from Today's Date.
This Integer routine is faster than <See Routine=ThisYear>.
@cat DTConv
@cat YearMath
}
function OptThisYear: Integer;
{: Returns the current Month - from Today's Date.
This Integer routine is faster than <See Routine=ThisMonth>.
@cat DTConv
@cat MonthMath
}
function OptThisMonth: Integer;
{: Returns the current Day - from Today's Date.
This Integer routine is faster than <See Routine=ThisDay>.
@cat DTConv
}
function OptThisDay: Integer;
{: Returns the Day Number in the Year represented by the given Date.
@param DT Date/Time to process.
@cat DTMath
@cat YearMath
}
function OptDayOfYear (const DT: TDateTime): Integer;
{: Returns the Day Number in this Year represented by today.
@cat DTMath
@cat YearMath
}
function OptThisDayOfYear: Integer;
{: Returns the number of days left in the Year represented by the given Date.
@param DT Date/Time to process.
@cat DTMath
@cat YearMath
}
function OptDaysLeftInYear (const DT: TDateTime): Integer;
{: Returns the number of days left in this Year.
@cat DTMath
@cat YearMath
}
function OptDaysLeftInThisYear: Integer;
//--- Year Based Routines ---
{: Is given Year a Leap Year. Thanks to Dr John Stockton
for suggesting a faster methodology.
@param Year the Year to be processed - should be 4 digit, eg 1999.
@cat YearMath
@cat DTComparison
}
function IsLeapYear (Year: Word): Boolean;
{: Returns the GoldenNumber for a given Year. Values are 1 -> 19.
The relationship between the Moon's Phases and the Year, repeats
itself every 19 years.
@param Year the Year to be processed - should be 4 digit, eg 1999.
@cat YearMath
}
function GetGoldenNumber (const Year: Word): Integer;
{: Return the Epact, which is a measure of the age of the moon (ie the number
of days that have passed since an "official" new moon) on a particular date.
@param Year the Year to be processed - should be 4 digit, eg 1999.
@cat YearMath
}
function GetEpact (const Year: Word): Integer;
{:Returns the Date of Easter Sunday for given Year - based on current Calendar.
@param Year the Year to be processed - should be 4 digit, eg 1999.
@cat YearMath
}
function GetEasterSunday (const Year: Word): TDateTime;
{:Returns the Date of Good Friday for given Year - based on current Calendar.
@param Year the Year to be processed - should be 4 digit, eg 1999.
@cat YearMath
}
function GetGoodFriday (const Year: Word): TDateTime;
{: Returns First Day of the Year, for a given Year.
@param Year the Year to be processed - should be 4 digit, eg 1999.
@cat YearMath
}
function GetFirstDayOfYear (const Year: Word): TDateTime;
{: Returns Last Day of the Year, for a given Year.
@param Year the Year to be processed - should be 4 digit, eg 1999.
@cat YearMath
}
function GetLastDayOfYear (const Year: Word): TDateTime;
{: Returns First Sunday of the Year, for a given Year. Used in
Week No Routines.
@param Year the Year to be processed - should be 4 digit, eg 1999.
@cat YearMath
@cat WeekMath
}
function GetFirstSundayOfYear (const Year: Word): TDateTime;
//--- Conversions ---
{: Returns Date as a String using ShortDateFormat from Regional
Settings. If the Date is Zero, then an Empty String will be returned.<p>
If an error occurs an Empty String is Returned.
@param DT Date/Time to Convert.
@cat DTConv
}
function Date2Str (const DT: TDateTime): String;
{: Returns the Day of the Month number from a given date/time.
@param DT Date/Time to Convert.
@returns the Day of the Month.
@cat DTConv
}
function Date2Day (const DT: TDateTime): Word;
{: Returns the Month number from a given date/time, 1 = Jan, etc.
@param DT Date/Time to Convert.
@returns the Month where 1 = Jan, through 12 = Dec.
@cat DTConv
@cat MonthMath
}
function Date2Month (const DT: TDateTime): Word;
{: Returns the Year from a given date/time.
@param DT Date/Time to Convert.
@returns the Year component, including Century.
@cat DTConv
@cat YearMath
}
function Date2Year (const DT: TDateTime): Word;
{: Returns the Time Portion as a string HH:MM with time separator
from the Regional Settings. If DT is 0, then an Empty String will be
returned.<p>
@param DT Date/Time to Convert.
@cat DTConv
}
function Time2Str (const DT: TDateTime): String;
{: Returns the Hour from a given date/time.
@param DT Date/Time to Convert.
@returns the Hour component.
@cat DTConv
}
function Time2Hr (const DT: TDateTime): Word;
{: Returns the Minute from a given date/time.
@param DT Date/Time to Convert.
@returns the Minute component.
@cat DTConv
}
function Time2Min (const DT: TDateTime): Word;
{: Returns the Second from a given date/time.
@param DT Date/Time to Convert.
@returns the Second component.
@cat DTConv
}
function Time2Sec (const DT: TDateTime): Word;
{: Returns the Millisecond from a given date/time.
@param DT Date/Time to Convert.
@returns the Millisecond component.
@cat DTConv
}
function Time2MSec (const DT: TDateTime): Word;
{: Returns the current Year - from Today's Date.
@cat DTConv
@cat YearMath
}
function ThisYear: Word;
{: Returns the current Month - from Today's Date.
@cat DTConv
@cat MonthMath
}
function ThisMonth: Word;
{: Returns the current Day - from Today's Date.
@cat DTConv
}
function ThisDay: Word;
{: Returns the current Hour - from the current Time.
@cat DTConv
}
function ThisHr: Word;
{: Returns the current Minute - from the current Time.
@cat DTConv
}
function ThisMin: Word;
{: Returns the current Second - from the current Time.
@cat DTConv
}
function ThisSec: Word;
{: Returns the current Millisecond - from the current Time.
@cat DTConv
}
function ThisMSec: Word;
{: Converts a string containing a Time into a DateTime.
@param S The String to convert.
@cat DTConv
}
function Str2Time (S: String): TDateTime;
{: Converts a string containing a Date into a DateTime. If the Item
has no month and/or year then the current month and year will be assumed. <p>
<See Var=ESB2DigitYr> contols the different ways in which 2 Digit Years
are handled in Str2Date.<p>
edyNone - Nothing is done, left to Delphi to handle. <p>
edyCutOff - the ESB2DigitCutOff is used to decide which century
the date lies in. If 1900 + Yr less than <See Var=ESB2DigitCutOff>
then it is assumed that 2000 + Yr is wanted, otherwise 1900 + Yr
is used.<p>
edyHistoric - asssumes that the yr is this year or earlier.
@param InDate The String to convert.
@cat DTConv
}
function Str2Date (S: String): TDateTime;
{: An enhanced routine to converts a string containing a Date into a DateTime,
donated by Tom Grieve. If the Item has no month and/or year then the current
month and year will be assumed. <p>
<See Var=ESB2DigitYr> contols the different ways in which 2 Digit Years
are handled in Str2Date.<p> This routine also handles Dates of the form
'03 Jun 2001' where the month is in alphabetic form.<p>
edyNone - Nothing is done, left to Delphi to handle. <p>
edyCutOff - the ESB2DigitCutOff is used to decide which century
the date lies in. If 1900 + Yr less than <See Var=ESB2DigitCutOff>
then it is assumed that 2000 + Yr is wanted, otherwise 1900 + Yr
is used.<p>
edyHistoric - asssumes that the yr is this year or earlier.
@param S The String to convert.
@cat DTConv
}
function EnhStr2Date (InDate: String): TDateTime;
{: Converts a string containing a Date into a DateTime. If the Item
has no month and/or year then the current month and year will be assumed. <p>
If a 2 Digit Year is used then it is assumted that it is this year or earlier.
@param S The String to convert.
@cat DTConv
}
function Str2HistoricDate (S: String): TDateTime;
{: Converts a string containing a Date into a DateTime. If the Item
has no month and/or year then the current month and year will be assumed. <p>
If a 2 Digit Year is used then CutOff is used to decide which century
the date lies in. If 1900 + Yr less than CutOff then it is assumed that
2000 + Yr is wanted, otherwise 1900 + Yr is used.
@param S The String to convert.
@cat DTConv
}
function Str2CutOffDate (S: string; const CutOff: Word): TDateTime;
{: Returns the Long Month Description for the supplied Date. Relies
on Regional Settings.
@param DT Date/Time to convert.
@returns the Long Month Name of the Month component.
@cat DTConv
@cat MonthMath
}
function Date2LongMonth (const DT: TDateTime): string;
{: Returns the Short Month Description for the supplied Date. Relies
on Regional Settings.
@param DT Date/Time to convert.
@returns the Short Month Name of the Month component.
@cat DTConv
@cat MonthMath
}
function Date2ShortMonth (const DT: TDateTime): string;
{: Returns the Long Day of Week Description for the supplied Date. Relies
on Regional Settings.
@param DT Date/Time to convert.
@returns the Long Day of Week Name for the given Date.
@cat DTConv
}
function Date2LongDOW (const DT: TDateTime): string;
{: Given a Month Name this routines searches through the Short and then
Long Month Names supplied in the Registry to do a Left Match, and
then return the Month Number. So for English Names, 'Ma' would return
3 for 'March' .
@param MonthName Name of the Month to search for.
@returns the Month Number, 1 through 12 - 0 implies not found.
@cat DTConv
@cat MonthMath
}
function MonthName2Month (const MonthName: string): Word;
{: Given a Day Name this routines searches through the Short and then
Long Day Names supplied in the Registry to do a Left Match, and
then return the Day Number. So for English Names, 'T' would return
3 for 'Tuesday'.
@param DayName Name of the Day of Week to search for.
@returns the DOW Number, 1 through 7 - 0 implies not found. 1 is Sunday.
@cat DTConv
}
function DayName2DOW (const DayName: string): Byte;
{: Converts a String in ISO Format, eg '2000-07-19 12:10:22' to a TDateTime.
Leading and trailing spaces are ignored - seconds can be omitted - in
fact the whole time can be omitted. Routine suggest by Wolfgang Werner.
@param ISODT String representing ISO Formatted Date Time - 'yyyy-mm-dd hh:mm:ss'.
@return String converted to TDateTime - 0 if any errors
@cat DTConv
}
function ISODateTime2DateTime (const ISODT: String): TDateTime;
{: Returns the number of Hours the specified number of Days represents.
@param Value Number of Days
@returns the Number of Hours
@cat DTConv
}
function Days2Hrs (const Value: Extended): Extended;
{: Returns the number of Days the specified number of Hours represents.
@param Value Number of Hours
@returns the Number of Days
@cat DTConv
}
function Hrs2Days (const Value: Extended): Extended;
{: Returns the number of Hours the specified number of Mintues represents.
@param Value Number of Minutes
@returns the Number of Hours
@cat DTConv
}
function Mins2Hrs (const Value: Extended): Extended;
{: Returns the number of Minutes the specified number of Hours represents.
@param Value Number of Hours
@returns the Number of Minutes
@cat DTConv
}
function Hrs2Mins (const Value: Extended): Extended;
{: Returns the number of Minutes the specified number of Seconds represents.
@param Value Number of Minutes
@returns the Number of Seconds
@cat DTConv
}
function Mins2Secs (const Value: Extended): Extended;
{: Returns the number of Seconds the specified number of Mintues represents.
@param Value Number of Seconds
@returns the Number of Minutes
@cat DTConv
}
function Secs2Mins (const Value: Extended): Extended;
{: Returns the number of Seconds the specified number of Days represents.
@param Value Number of Days
@returns the Number of Seconds
@cat DTConv
}
function Days2Secs (const Value: Extended): Extended;
{: Returns the number of Days the specified number of Seconds represents.
@param Value Number of Seconds
@returns the Number of Days
@cat DTConv
}
function Secs2Days (const Value: Extended): Extended;
{: Returns the number of Hours the specified number of Seconds represents.
@param Value Number of Seconds
@returns the Number of Hours
@cat DTConv
}
function Secs2Hrs (const Value: Extended): Extended;
{: Returns the number of Seconds the specified number of Hours represents.
@param Value Number of Hours
@returns the Number of Seconds
@cat DTConv
}
function Hrs2Secs (const Value: Extended): Extended;
{: Returns the number of Minutes the specified number of Days represents.
@param Value Number of Days
@returns the Number of Minutes
@cat DTConv
}
function Days2Mins (const Value: Extended): Extended;
{: Returns the number of Days the specified number of Minutes represents.
@param Value Number of Minutes
@returns the Number of Days
@cat DTConv
}
function Mins2Days (const Value: Extended): Extended;
{: Returns the number of Weeks the specified number of Days represents.
@param Value Number of Days
@returns the Number of Weeks
@cat DTConv
}
function Days2Weeks (const Value: Extended): Extended;
{: Returns the number of Days the specified number of Weeks represents.
@param Value Number of Weeks
@returns the Number of Days
@cat DTConv
}
function Weeks2Days (const Value: Extended): Extended;
{: Returns the number of Fortnights the specified number of Days represents.
@param Value Number of Days
@returns the Number of Fortnights
@cat DTConv
}
function Days2Fortnights (const Value: Extended): Extended;
{: Returns the number of Days the specified number of Fortnights represents.
@param Value Number of Fortnights
@returns the Number of Days
@cat DTConv
}
function Fortnights2Days (const Value: Extended): Extended;
{: Returns the number of Months the specified number of Days represents. Months
are based on Synodic Months - see <See Const=DaysPerSynodicMonth>.
@param Value Number of Days
@returns the Number of Months
@cat DTConv
}
function Days2Months (const Value: Extended): Extended;
{: Returns the number of Days the specified number of Months represents. Months
are based on Synodic Months - see <See Const=DaysPerSynodicMonth>.
@param Value Number of Months (Synodic)
@returns the Number of Days
@cat DTConv
}
function Months2Days (const Value: Extended): Extended;
{: Returns the number of Years the specified number of Days represents. Years
are based on Tropical Years - see <See Const=DaysPerTropicalYear>.
@param Value Number of Days
@returns the Number of Years (Tropical)
@cat DTConv
}
function Days2Years (const Value: Extended): Extended;
{: Returns the number of Days the specified number of Years represents. Months
are based on Tropical years - see <See Const=DaysPerTropicalYear>.
@param Value Number of Years (Tropical)
@returns the Number of Days
@cat DTConv
}
function Years2Days (const Value: Extended): Extended;
{: Returns the number of Years the specified number of Days represents. Years
are based on Gregorian Years - see <See Const=DaysPerGregorianYear>.
@param Value Number of Days
@returns the Number of Years (Gregorian)
@cat DTConv
}
function Days2YearsGregorian (const Value: Extended): Extended;
{: Returns the number of Days the specified number of Years represents. Months
are based on Gregorian years - see <See Const=DaysPerGregorianYear>.
@param Value Number of Years (Gregorian)
@returns the Number of Days
@cat DTConv
}
function YearsGregorian2Days (const Value: Extended): Extended;
{: Returns the number of Years the specified number of Days represents. Years
are based on Julian Years - see <See Const=DaysPerJulianYear>.
@param Value Number of Days
@returns the Number of Years (Julian)
@cat DTConv
}
function Days2YearsJulian (const Value: Extended): Extended;
{: Returns the number of Days the specified number of Years represents. Months
are based on Julian years - see <See Const=DaysPerJulianYear>.
@param Value Number of Years (Julian)
@returns the Number of Days
@cat DTConv
}
function YearsJulian2Days (const Value: Extended): Extended;
{: Converts a quantity of seconds into a String of the form 'h:mm:ss'.
Routine proposed by Joel Joly.
@cat DTConv
}
function Sec2TimeStr (Sec : LongInt): string;
//--- Date/Time Arithmetic ---
{: Returns the number of whole minutes apart the two times are (date portion ignored)
and DT1 is assumed to be before DT2.
@param DT1 First Time, Date portion ignores - assumed to be the earlier time.
@param DT2 Second Time, Date portion ignores - assumed to be the later time.
@cat DTMath
}
function MinutesApart (const DT1, DT2: TDateTime): Word;
{: Returns the decimal number of Days apart the two date/times are. If 0 then
they are the same Date/Time, if negative then DT1 occurs after DT2 DT2.
@param DT1 First Date/Time to process.
@param DT2 Second DateTime to process.
@cat DTMath
}
function TimeApartInDays (const DT1, DT2: TDateTime): Extended;
{: Returns the decimal number of Weeks apart the two date/times are. If 0 then
they are the same Date/Time, if negative then DT1 occurs after DT2 DT2.
@param DT1 First Date/Time to process.
@param DT2 Second DateTime to process.
@cat DTMath
}
function TimeApartInWeeks (const DT1, DT2: TDateTime): Extended;
{: Returns the decimal number of fortnights apart the two date/times are. If 0 then
they are the same Date/Time, if negative then DT1 occurs after DT2 DT2.
@param DT1 First Date/Time to process.
@param DT2 Second DateTime to process.
@cat DTMath
}
function TimeApartInFortnights (const DT1, DT2: TDateTime): Extended;
{: Returns the decimal number of hours apart the two date/times are. If 0 then
they are the same Date/Time, if negative then DT1 occurs after DT2 DT2.
@param DT1 First Date/Time to process.
@param DT2 Second DateTime to process.
@cat DTMath
}
function TimeApartInHrs (const DT1, DT2: TDateTime): Extended;
{: Returns the decimal number of Minutes apart the two date/times are. If 0 then
they are the same Date/Time, if negative then DT1 occurs after DT2 DT2.
@param DT1 First Date/Time to process.
@param DT2 Second DateTime to process.
@cat DTMath
}
function TimeApartInMins (const DT1, DT2: TDateTime): Extended;
{: Returns the decimal number of Seconds apart the two date/times are. If 0 then
they are the same Date/Time, if negative then DT1 occurs after DT2 DT2.
@param DT1 First Date/Time to process.
@param DT2 Second DateTime to process.
@cat DTMath
}
function TimeApartInSecs (const DT1, DT2: TDateTime): Extended;
{: Converts a time in MilliSeconds to a string of the form 'H:MM:SS.mmm'.
@param MS Value in Milliseconds.
@cat DTMath
}
function MS2TimeStr (const MS: LongInt): String;
{: Returns the current date/time as a string in the Format of: YYYYMMDD-HHMMSSmmm.
@cat DTMath
}
function GetDateTimeStamp: String;
{: Adjusts the date so that it has the Year specified. Makes 29 Feb of any
year that is not a Leap year 1 Mar.
@param D Date/Time to process.
@param Year Year to make the date in, eg 1999.
@cat DTMath
@cat YearMath
}
function AdjustDateYear (const D: TDateTime; const Year: Word): TDateTime;
{: Adds a Floating Point amount of Seconds to a Given Date/Time.