13 IdMilliSecondsInSecond
= 1000;
14 IdSecondsInMinute
= 60;
20 IdDaysInLeapYear
= 366;
21 IdYearsInShortLeapYearCycle
= 4;
22 IdDaysInShortLeapYearCycle
= IdDaysInLeapYear
+ (IdDaysInYear
* 3);
23 IdDaysInShortNonLeapYearCycle
= IdDaysInYear
* IdYearsInShortLeapYearCycle
;
24 IdDaysInFourYears
= IdDaysInShortLeapYearCycle
;
25 IdYearsInCentury
= 100;
26 IdDaysInCentury
= (25 * IdDaysInFourYears
) - 1;
27 IdDaysInLeapCentury
= IdDaysInCentury
+ 1;
28 IdYearsInLeapYearCycle
= 400;
29 IdDaysInLeapYearCycle
= IdDaysInCentury
* 4 + 1;
35 IdHoursInHalfDay
= IdHoursInDay
div 2;
37 IdSecondsInHour
= IdSecondsInMinute
* IdMinutesInHour
;
38 IdSecondsInDay
= IdSecondsInHour
* IdHoursInDay
;
39 IdSecondsInHalfDay
= IdSecondsInHour
* IdHoursInHalfDay
;
40 IdSecondsInWeek
= IdDaysInWeek
* IdSecondsInDay
;
41 IdSecondsInYear
= IdSecondsInDay
* IdDaysInYear
;
42 IdSecondsInLeapYear
= IdSecondsInDay
* IdDaysInLeapYear
;
44 IdMillisecondsInMinute
= IdSecondsInMinute
* IdMillisecondsInSecond
;
45 IdMillisecondsInHour
= IdSecondsInHour
* IdMillisecondsInSecond
;
46 IdMillisecondsInDay
= IdSecondsInDay
* IdMillisecondsInSecond
;
47 IdMillisecondsInWeek
= IdSecondsInWeek
* IdMillisecondsInSecond
;
49 IdDaysInMonth
: array[1..IdMonthsInYear
] of byte =
51 31, 28, 31, 30, 31, 30,
52 31, 31, 30, 31, 30, 31
55 IdMonthNames
: array[0..IdMonthsInYear
] of string =
57 SLongMonthNameJan
, SLongMonthNameFeb
, SLongMonthNameMar
,
58 SLongMonthNameApr
, SLongMonthNameMay
, SLongMonthNameJun
,
59 SLongMonthNameJul
, SLongMonthNameAug
, SLongMonthNameSep
,
60 SLongMonthNameOct
, SLongMonthNameNov
, SLongMonthNameDec
);
62 IdMonthShortNames
: array[0..IdMonthsInYear
] of string =
64 SShortMonthNameJan
, SShortMonthNameFeb
, SShortMonthNameMar
,
65 SShortMonthNameApr
, SShortMonthNameMay
, SShortMonthNameJun
,
66 SShortMonthNameJul
, SShortMonthNameAug
, SShortMonthNameSep
,
67 SShortMonthNameOct
, SShortMonthNameNov
, SShortMonthNameDec
);
69 IdDayNames
: array[0..IdDaysInWeek
] of string =
70 ('', SLongDayNameSun
, SLongDayNameMon
, SLongDayNameTue
,
71 SLongDayNameWed
, SLongDayNameThu
, SLongDayNameFri
,
74 IdDayShortNames
: array[0..IdDaysInWeek
] of string =
75 ('', SShortDayNameSun
, SShortDayNameMon
, SShortDayNameTue
,
76 SShortDayNameWed
, SShortDayNameThu
, SShortDayNameFri
,
80 TZ_NZDT
= 13; // New Zealand Daylight Time
81 TZ_IDLE
= 12; // International Date Line East
82 TZ_NZST
= TZ_IDLE
; // New Zealand Standard Time
83 TZ_NZT
= TZ_IDLE
; // New Zealand Time
84 TZ_EADT
= 11; // Eastern Australian Daylight Time
85 TZ_GST
= 10; // Guam Standard Time / Russia Zone 9
86 TZ_JST
= 9; // Japan Standard Time / Russia Zone 8
87 TZ_CCT
= 8; // China Coast Time / Russia Zone 7
88 TZ_WADT
= TZ_CCT
; // West Australian Daylight Time
89 TZ_WAST
= 7; // West Australian Standard Time / Russia Zone 6
90 TZ_ZP6
= 6; // Chesapeake Bay / Russia Zone 5
91 TZ_ZP5
= 5; // Chesapeake Bay / Russia Zone 4
92 TZ_ZP4
= 4; // Russia Zone 3
93 TZ_BT
= 3; // Baghdad Time / Russia Zone 2
94 TZ_EET
= 2; // Eastern European Time / Russia Zone 1
95 TZ_MEST
= TZ_EET
; // Middle European Summer Time
96 TZ_MESZ
= TZ_EET
; // Middle European Summer Zone
97 TZ_SST
= TZ_EET
; // Swedish Summer Time
98 TZ_FST
= TZ_EET
; // French Summer Time
99 TZ_CET
= 1; // Central European Time
100 TZ_FWT
= TZ_CET
; // French Winter Time
101 TZ_MET
= TZ_CET
; // Middle European Time
102 TZ_MEWT
= TZ_CET
; // Middle European Winter Time
103 TZ_SWT
= TZ_CET
; // Swedish Winter Time
104 TZ_GMT
= 0; // Greenwich Meanttime
105 TZ_UT
= TZ_GMT
; // Universla Time
106 TZ_UTC
= TZ_GMT
; // Universal Time Co-ordinated
107 TZ_WET
= TZ_GMT
; // Western European Time
108 TZ_WAT
= -1; // West Africa Time
109 TZ_BST
= TZ_WAT
; // British Summer Time
110 TZ_AT
= -2; // Azores Time
111 TZ_ADT
= -3; // Atlantic Daylight Time
112 TZ_AST
= -4; // Atlantic Standard Time
113 TZ_EDT
= TZ_AST
; // Eastern Daylight Time
114 TZ_EST
= -5; // Eastern Standard Time
115 TZ_CDT
= TZ_EST
; // Central Daylight Time
116 TZ_CST
= -6; // Central Standard Time
117 TZ_MDT
= TZ_CST
; // Mountain Daylight Time
118 TZ_MST
= -7; // Mountain Standard Time
119 TZ_PDT
= TZ_MST
; // Pacific Daylight Time
120 TZ_PST
= -8; // Pacific Standard Time
121 TZ_YDT
= TZ_PST
; // Yukon Daylight Time
122 TZ_YST
= -9; // Yukon Standard Time
123 TZ_HDT
= TZ_YST
; // Hawaii Daylight Time
124 TZ_AHST
= -10; // Alaska-Hawaii Standard Time
125 TZ_CAT
= TZ_AHST
; // Central Alaska Time
126 TZ_HST
= TZ_AHST
; // Hawaii Standard Time
127 TZ_EAST
= TZ_AHST
; // East Australian Standard Time
128 TZ_NT
= -11; // -None-
129 TZ_IDLW
= -12; // International Date Line West
131 // Military Time Zones
157 TZM_November
= TZM_N
;
185 TDays
= (TDaySun
, TDayMon
, TDayTue
, TDayWed
, TDayThu
, TDayFri
, TDaySat
);
186 TMonths
= (TMthJan
, TMthFeb
, TMthMar
, TMthApr
, TMthMay
, TMthJun
,
187 TMthJul
, TMthAug
, TMthSep
, TMthOct
, TMthNov
, TMthDec
);
189 TIdDateTimeStamp
= object(TIdBaseComponent
)
192 FIsLeapYear
: Boolean;
193 FMillisecond
: Integer;
194 FRequestedTimeZone
: Integer;
199 procedure CheckLeapYear
;
201 { constructor Create(AOwner: TComponent); override;
202 } destructor Destroy
;
204 virtual; procedure AddDays(ANumber
: Cardinal);
205 procedure AddHours(ANumber
: Cardinal);
206 procedure AddMilliseconds(ANumber
: Cardinal);
207 procedure AddMinutes(ANumber
: Cardinal);
208 procedure AddMonths(ANumber
: Cardinal);
209 procedure AddSeconds(ANumber
: Cardinal);
210 procedure AddTDateTime(ADateTime
: TDateTime
);
211 procedure AddTIdDateTimeStamp(AIdDateTime
: TIdDateTimeStamp
);
212 procedure AddTTimeStamp(ATimeStamp
: TTimeStamp
);
213 procedure AddWeeks(ANumber
: Cardinal);
214 procedure AddYears(ANumber
: Cardinal);
216 function GetAsISO8601Calendar
: string;
217 function GetAsISO8601Ordinal
: string;
218 function GetAsISO8601Week
: string;
219 function GetAsRFC882
: string;
221 function GetAsTDateTime
: TDateTime
;
222 function GetAsTTimeStamp
: TTimeStamp
;
223 function GetAsTimeOFDay
: string; // HH:MM:SS
225 function GetBeatOFDay
: Integer;
226 function GetDaysInYear
: Integer;
227 function GetDayOfMonth
: Integer;
228 function GetDayOfWeek
: Integer;
229 function GetDayOfWeekName
: string;
230 function GetDayOfWeekShortName
: string;
231 function GetHourOf12Day
: Integer;
232 function GetHourOf24Day
: Integer;
233 function GetIsMorning
: Boolean;
234 function GetMinuteOFDay
: Integer;
235 function GetMinuteOfHour
: Integer;
236 function GetMonthOFYear
: Integer;
237 function GetMonthName
: string;
238 function GetMonthShortName
: string;
239 function GetSecondsInYear
: Integer;
240 function GetSecondOfMinute
: Integer;
241 function GetWeekOFYear
: Integer;
243 procedure SetFromTDateTime(ADateTime
: TDateTime
);
244 procedure SetFromTTimeStamp(ATimeStamp
: TTimeStamp
);
246 procedure SetDay(ANumber
: Integer);
247 procedure SetMillisecond(ANumber
: Integer);
248 procedure SetSecond(ANumber
: Integer);
249 procedure SetYear(ANumber
: Integer);
251 procedure SubtractDays(ANumber
: Cardinal);
252 procedure SubtractHours(ANumber
: Cardinal);
253 procedure SubtractMilliseconds(ANumber
: Cardinal);
254 procedure SubtractMinutes(ANumber
: Cardinal);
255 procedure SubtractMonths(ANumber
: Cardinal);
256 procedure SubtractSeconds(ANumber
: Cardinal);
257 procedure SubtractTDateTime(ADateTime
: TDateTime
);
258 procedure SubtractTIdDateTimeStamp(AIdDateTime
: TIdDateTimeStamp
);
259 procedure SubtractTTimeStamp(ATimeStamp
: TTimeStamp
);
260 procedure SubtractWeeks(ANumber
: Cardinal);
261 procedure SubtractYears(ANumber
: Cardinal);
263 property AsISO8601Calendar
: string read GetAsISO8601Calendar
;
264 property AsISO8601Ordinal
: string read GetAsISO8601Ordinal
;
265 property AsISO8601Week
: string read GetAsISO8601Week
;
266 property AsRFC822
: string read GetAsRFC882
;
267 property AsTDateTime
: TDateTime read GetAsTDateTime
;
268 property AsTTimeStamp
: TTimeStamp read GetAsTTimeStamp
;
269 property AsTimeOFDay
: string read GetAsTimeOFDay
;
270 property BeatOFDay
: Integer read GetBeatOFDay
;
271 property Day
: Integer read FDay write FDay
;
272 property DaysInYear
: Integer read GetDaysInYear
;
273 property DayOfMonth
: Integer read GetDayOfMonth
;
274 property DayOfWeek
: Integer read GetDayOfWeek
;
275 property DayOfWeekName
: string read GetDayOfWeekName
;
276 property DayOfWeekShortName
: string read GetDayOfWeekShortName
;
277 property HourOf12Day
: Integer read GetHourOf12Day
;
278 property HourOf24Day
: Integer read GetHourOf24Day
;
279 property IsLeapYear
: Boolean read FIsLeapYear
;
280 property IsMorning
: Boolean read GetIsMorning
;
281 property Second
: Integer read FSecond write FSecond
;
282 property SecondsInYear
: Integer read GetSecondsInYear
;
283 property SecondOfMinute
: Integer read GetSecondOfMinute
;
284 property MinuteOFDay
: Integer read GetMinuteOFDay
;
285 property MinuteOfHour
: Integer read GetMinuteOfHour
;
286 property MonthOFYear
: Integer read GetMonthOFYear
;
287 property MonthName
: string read GetMonthName
;
288 property MonthShortName
: string read GetMonthShortName
;
289 property Millisecond
: Integer read FMillisecond write FMillisecond
;
290 property TimeZone
: Integer read FTimeZone write FTimeZone
;
291 property Year
: Integer read FYear write SetYear
;
292 property WeekOFYear
: Integer read GetWeekOFYear
;
294 PIdDateTimeStamp
=^TIdDateTimeStamp
;
295 function NewIdDateTimeStamp(AOwner
: PControl
):PIdDateTimeStamp
;
301 MaxWeekAdd
: Cardinal = $FFFFFFFF div IdDaysInWeek
;
302 MaxMinutesAdd
: Cardinal = $FFFFFFFF div IdSecondsInMinute
;
304 //constructor TIdDateTimeStamp.Create;
305 function NewIdDateTimeStamp(AOwner
: PControl
):PIdDateTimeStamp
;
307 New( Result
, Create
);
310 // inherited Create(AOwner);
316 FRequestedTimeZone
:= 0;
320 destructor TIdDateTimeStamp
.Destroy
;
325 procedure TIdDateTimeStamp
.AddDays
;
329 if (ANumber
> Cardinal(DaysInYear
- FDay
)) and (not (FDay
= 1)) then
331 ANumber
:= ANumber
- Cardinal(DaysInYear
- FDay
);
337 FDay
:= FDay
+ Integer(ANumber
);
341 if ANumber
>= IdDaysInLeapYearCycle
then
343 i
:= ANumber
div IdDaysInLeapYearCycle
;
344 AddYears(i
* IdYearsInLeapYearCycle
);
345 ANumber
:= ANumber
- Cardinal(i
* IdDaysInLeapYearCycle
);
348 if ANumber
>= IdDaysInLeapCentury
then
350 while ANumber
>= IDDaysInLeapCentury
do
356 AddYears(IdYearsInCentury
);
357 ANumber
:= ANumber
- Cardinal(IdDaysInLeapCentury
);
361 AddYears(IdYearsInCentury
);
362 ANumber
:= ANumber
- Cardinal(IdDaysInCentury
);
367 if ANumber
>= IdDaysInShortLeapYearCycle
then
369 i
:= ANumber
div IdDaysInShortLeapYearCycle
;
370 AddYears(i
* IdYearsInShortLeapYearCycle
);
371 ANumber
:= ANumber
- Cardinal(i
* IdDaysInShortLeapYearCycle
);
375 while Integer(ANumber
) > i
do
382 if FDay
+ Integer(ANumber
) > i
then
385 Dec(ANumber
, i
- FDay
);
394 procedure TIdDateTimeStamp
.AddHours
;
398 i
:= ANumber
div IdHoursInDay
;
400 Dec(ANumber
, i
* IdHoursInDay
);
401 AddSeconds(ANumber
* IdSecondsInHour
);
404 procedure TIdDateTimeStamp
.AddMilliseconds
;
408 i
:= ANumber
div IdMillisecondsInDay
;
412 Dec(ANumber
, i
* IdMillisecondsInDay
);
415 i
:= ANumber
div IdMillisecondsInSecond
;
419 Dec(ANumber
, i
* IdMillisecondsInSecond
);
422 Inc(FMillisecond
, ANumber
);
423 while FMillisecond
> IdMillisecondsInSecond
do
426 Dec(FMillisecond
, IdMillisecondsInSecond
);
430 procedure TIdDateTimeStamp
.AddMinutes
;
432 while ANumber
> MaxMinutesAdd
do
434 AddSeconds(MaxMinutesAdd
);
435 Dec(ANumber
, MaxMinutesAdd
);
438 AddSeconds(ANumber
* IdSecondsInMinute
);
441 procedure TIdDateTimeStamp
.AddMonths
;
445 i
:= ANumber
div IdMonthsInYear
;
447 Dec(ANumber
, i
* IdMonthsInYear
);
456 if (i
= 2) and (IsLeapYear
) then
458 AddDays(IdDaysInMonth
[i
] + 1);
462 AddDays(IdDaysInMonth
[i
]);
469 procedure TIdDateTimeStamp
.AddSeconds
;
473 i
:= ANumber
div IdSecondsInDay
;
477 ANumber
:= ANumber
- (i
* IdSecondsInDay
);
480 Inc(FSecond
, ANumber
);
481 while FSecond
> IdSecondsInDay
do
484 Dec(FSecond
, IdSecondsInDay
);
488 procedure TIdDateTimeStamp
.AddTDateTime
;
490 AddTTimeStamp(DateTimeToTimeStamp(ADateTime
));
493 procedure TIdDateTimeStamp
.AddTIdDateTimeStamp
;
495 AddYears(AIdDateTime
.Year
);
496 AddDays(AIdDateTime
.Day
);
497 AddSeconds(AIdDateTime
.Second
);
498 AddMilliseconds(AIdDateTime
.Millisecond
);
501 procedure TIdDateTimeStamp
.AddTTimeStamp
;
503 TId
: TIdDateTimeStamp
;
505 { TId := TIdDateTimeStamp.Create(Self);
507 TId.SetFromTTimeStamp(ATimeStamp);
508 Self.AddTIdDateTimeStamp(TId);
514 procedure TIdDateTimeStamp
.AddWeeks
;
516 while ANumber
> MaxWeekAdd
do
519 Dec(ANumber
, MaxWeekAdd
);
522 AddDays(ANumber
* IdDaysInWeek
);
525 procedure TIdDateTimeStamp
.AddYears
;
527 if (FYear
<= -1) and (Integer(ANumber
) >= -FYear
) then
535 procedure TIdDateTimeStamp
.CheckLeapYear
;
537 if FYear
mod 4 = 0 then
539 if FYear
mod 100 = 0 then
541 if FYear
mod 400 = 0 then
547 FIsLeapYear
:= False;
557 FIsLeapYear
:= False;
561 function TIdDateTimeStamp
.GetAsISO8601Calendar
;
563 result
:= IntToStr(FYear
) + '-';
564 result
:= result
+ IntToStr(MonthOFYear
) + '-';
565 result
:= result
+ IntToStr(DayOfMonth
) + 'T';
566 result
:= result
+ AsTimeOFDay
;
569 function TIdDateTimeStamp
.GetAsISO8601Ordinal
: string;
571 result
:= IntToStr(FYear
) + '-';
572 result
:= result
+ IntToStr(FDay
) + 'T';
573 result
:= result
+ AsTimeOFDay
;
576 function TIdDateTimeStamp
.GetAsISO8601Week
: string;
578 result
:= IntToStr(FYear
) + '-W';
579 result
:= result
+ IntToStr(WeekOFYear
) + '-';
580 result
:= result
+ IntToStr(DayOfWeek
) + 'T';
581 result
:= result
+ AsTimeOFDay
;
584 function TIdDateTimeStamp
.GetAsRFC882
;
586 result
:= IdDayShortNames
[DayOfWeek
] + ', ';
587 result
:= result
+ IntToStr(DayOfMonth
) + ' ';
588 result
:= result
+ IdMonthShortNames
[MonthOFYear
] + ' ';
589 result
:= result
+ IntToStr(Year
) + ' ';
590 result
:= result
+ AsTimeOFDay
+ ' ';
591 if FTimeZone
< -9 then
593 result
:= result
+ IntToStr(FTimeZone
) + '00';
596 if FTimeZone
> 9 then
598 result
:= result
+ '+' + IntToStr(FTimeZone
) + '00';
601 if FTimeZone
>= 0 then
603 result
:= result
+ '+0' + IntToStr(FTimeZone
) + '00';
607 result
:= result
+ '-0' + IntToStr(0 - FTimeZone
) + '00';
612 function TIdDateTimeStamp
.GetAsTDateTime
;
614 result
:= TimeStampToDateTime(GetAsTTimeStamp
);
617 function TIdDateTimeStamp
.GetAsTTimeStamp
;
619 NonLeap
, Leap
: Integer;
621 Leap
:= FYear
div 400;
622 NonLeap
:= (FYear
div 100) - Leap
;
623 Leap
:= (FYear
div 4) - NonLeap
;
624 result
.Date
:= (Leap
* IdDaysInLeapYear
) + (NonLeap
* IdDaysInYear
) +
626 result
.Time
:= (FSecond
* IdMillisecondsInSecond
) + FMillisecond
;
629 function TIdDateTimeStamp
.GetAsTimeOFDay
;
636 result
:= result
+ '0' + IntToStr(i
) + ':';
640 result
:= result
+ IntToStr(i
) + ':';
642 i
:= MinuteOfHour
- 1;
645 result
:= result
+ '0' + IntToStr(i
) + ':';
649 result
:= result
+ IntToStr(i
) + ':';
651 i
:= SecondOfMinute
- 1;
654 result
:= result
+ '0' + IntToStr(i
) + ' ';
658 result
:= result
+ IntToStr(i
) + ' ';
662 function TIdDateTimeStamp
.GetBeatOFDay
;
667 // i64 := (FSecond) * IdBeatsInDay;
668 // i64 := i64 div IdSecondsInDay;
669 // result := Integer(i64);
672 function TIdDateTimeStamp
.GetDaysInYear
;
676 result
:= IdDaysInLeapYear
;
680 result
:= IdDaysInYear
;
684 function TIdDateTimeStamp
.GetDayOfMonth
;
686 count
, mnth
, days
: Integer;
689 if IsLeapYear
and (mnth
> 2) then
697 for count
:= 1 to mnth
- 1 do
699 Inc(days
, IdDaysInMonth
[count
]);
712 function TIdDateTimeStamp
.GetDayOfWeek
;
714 a
, y
, m
, d
, mnth
: Integer;
716 // Thanks to the "FAQ About Calendars" by Claus Tøndering for this algorithm
717 // http://www.tondering.dk/claus/calendar.html
719 a
:= (14 - mnth
) div 12;
721 m
:= mnth
+ (12 * a
) - 2;
722 d
:= DayOfMonth
+ y
+ (y
div 4) - (y
div 100) + (y
div 400) + ((31 * m
) div
728 function TIdDateTimeStamp
.GetDayOfWeekName
;
730 result
:= IdDayNames
[GetDayOfWeek
];
733 function TIdDateTimeStamp
.GetDayOfWeekShortName
;
735 result
:= IdDayShortNames
[GetDayOfWeek
];
738 function TIdDateTimeStamp
.GetHourOf12Day
;
742 hr
:= GetHourOf24Day
;
750 function TIdDateTimeStamp
.GetHourOf24Day
;
752 result
:= (Second
- 1) div IdSecondsInHour
;
755 function TIdDateTimeStamp
.GetIsMorning
;
757 if Second
<= (IdSecondsInHalFDay
+ 1) then
767 function TIdDateTimeStamp
.GetMinuteOFDay
;
769 result
:= Second
div IdSecondsInMinute
;
772 function TIdDateTimeStamp
.GetMinuteOfHour
;
774 result
:= GetMinuteOFDay
- (IdMinutesInHour
* (GetHourOf24Day
));
777 function TIdDateTimeStamp
.GetMonthOFYear
;
797 if Today
> IdDaysInMonth
[Count
] + AddOne
then
799 Dec(Today
, IdDaysInMonth
[Count
] + AddOne
);
809 if Today
> IdDaysInMonth
[Count
] then
811 Dec(Today
, IdDaysInMonth
[Count
]);
823 function TIdDateTimeStamp
.GetMonthName
;
825 result
:= IdMonthNames
[MonthOFYear
];
828 function TIdDateTimeStamp
.GetMonthShortName
;
830 result
:= IdMonthShortNames
[MonthOFYear
];
833 function TIdDateTimeStamp
.GetSecondsInYear
;
837 result
:= IdSecondsInLeapYear
;
841 result
:= IdSecondsInYear
;
845 function TIdDateTimeStamp
.GetSecondOfMinute
;
847 result
:= FSecond
- (GetMinuteOFDay
* IdSecondsInMinute
);
850 function TIdDateTimeStamp
.GetWeekOFYear
;
853 DT
: TIdDateTimeStamp
;
855 { DT := TIdDateTimeStamp.Create(Self);
867 procedure TIdDateTimeStamp
.SetFromTDateTime
;
869 SetFromTTimeStamp(DateTimeToTimeStamp(ADateTime
));
872 procedure TIdDateTimeStamp
.SetFromTTimeStamp
;
877 SetMillisecond(ATimeStamp
.Time
);
878 SetDay(ATimeStamp
.Date
);
881 procedure TIdDateTimeStamp
.SetDay
;
887 procedure TIdDateTimeStamp
.SetMillisecond
;
890 AddMilliseconds(ANumber
);
893 procedure TIdDateTimeStamp
.SetSecond
;
899 procedure TIdDateTimeStamp
.SetYear
;
909 procedure TIdDateTimeStamp
.SubtractDays
;
913 if ANumber
>= Cardinal(FDay
- 1) then
915 ANumber
:= ANumber
- Cardinal(FDay
- 1);
920 FDay
:= FDay
- Integer(ANumber
);
923 if ANumber
>= IdDaysInLeapYearCycle
then
925 i
:= ANumber
div IdDaysInLeapYearCycle
;
926 SubtractYears(i
* IdYearsInLeapYearCycle
);
927 ANumber
:= ANumber
- Cardinal(i
* IdDaysInLeapYearCycle
);
930 if ANumber
>= IdDaysInLeapCentury
then
932 while ANumber
>= IdDaysInLeapCentury
do
938 SubtractYears(IdYearsInCentury
);
939 ANumber
:= ANumber
- Cardinal(IdDaysInLeapCentury
);
943 SubtractYears(IdYearsInCentury
);
944 ANumber
:= ANumber
- Cardinal(IdDaysInCentury
);
949 if ANumber
>= IdDaysInShortLeapYearCycle
then
951 while ANumber
>= IdDaysInShortLeapYearCycle
do
954 i
:= (FYear
shr 2) shl 2;
956 if SysUtils
.IsLeapYear(i
) then
958 SubtractYears(IdYearsInShortLeapYearCycle
);
959 ANumber
:= ANumber
- Cardinal(IdDaysInShortLeapYearCycle
);
963 SubtractYears(IdYearsInShortLeapYearCycle
);
964 ANumber
:= ANumber
- Cardinal(IdDaysInShortNonLeapYearCycle
);
969 while ANumber
> Cardinal(DaysInYear
) do
972 Dec(ANumber
, DaysInYear
);
973 if Self
.IsLeapYear
then
979 if ANumber
>= Cardinal(FDay
) then
982 ANumber
:= ANumber
- Cardinal(FDay
);
983 Day
:= DaysInYear
- Integer(ANumber
);
992 procedure TIdDateTimeStamp
.SubtractHours
;
996 i
:= ANumber
div IdHoursInDay
;
998 Dec(ANumber
, i
* IdHoursInDay
);
1000 SubtractSeconds(ANumber
* IdSecondsInHour
);
1003 procedure TIdDateTimeStamp
.SubtractMilliseconds
;
1007 i
:= ANumber
div IdMillisecondsInDay
;
1009 Dec(ANumber
, i
* IdMillisecondsInDay
);
1011 i
:= ANumber
div IdMillisecondsInSecond
;
1013 Dec(ANumber
, i
* IdMillisecondsInSecond
);
1015 Dec(FMillisecond
, ANumber
);
1016 while FMillisecond
<= 0 do
1019 FMillisecond
:= IdMillisecondsInSecond
- FMillisecond
;
1023 procedure TIdDateTimeStamp
.SubtractMinutes(ANumber
: Cardinal);
1025 while ANumber
> MaxMinutesAdd
do
1027 SubtractSeconds(MaxMinutesAdd
* IdSecondsInMinute
);
1028 Dec(ANumber
, MaxMinutesAdd
);
1030 SubtractSeconds(ANumber
* IdSecondsInMinute
);
1033 procedure TIdDateTimeStamp
.SubtractMonths
;
1037 i
:= ANumber
div IdMonthsInYear
;
1039 Dec(ANumber
, i
* IdMonthsInYear
);
1041 while ANumber
> 0 do
1048 if (i
= 3) and (IsLeapYear
) then
1050 SubtractDays(IdDaysInMonth
[2] + 1);
1054 SubtractDays(IdDaysInMonth
[i
- 1]);
1060 procedure TIdDateTimeStamp
.SubtractSeconds(ANumber
: Cardinal);
1064 i
:= ANumber
div IdSecondsInDay
;
1066 Dec(ANumber
, i
* IdSecondsInDay
);
1068 Dec(FSecond
, ANumber
);
1069 if FSecond
<= 0 then
1072 FSecond
:= IdSecondsInDay
+ FSecond
;
1076 procedure TIdDateTimeStamp
.SubtractTDateTime
;
1078 SubtractTTimeStamp(DateTimeToTimeStamp(ADateTime
));
1081 procedure TIdDateTimeStamp
.SubtractTIdDateTimeStamp
;
1083 SubtractYears(AIdDateTime
.Year
);
1084 SubtractDays(AIdDateTime
.Day
);
1085 SubtractSeconds(AIdDateTime
.Second
);
1086 SubtractMilliseconds(AIdDateTime
.Millisecond
);
1089 procedure TIdDateTimeStamp
.SubtractTTimeStamp
;
1091 TId
: TIdDateTimeStamp
;
1093 { TId := TIdDateTimeStamp.Create(Self);
1095 TId.SetFromTTimeStamp(ATimeStamp);
1096 Self.SubtractTIdDateTimeStamp(TId);
1102 procedure TIdDateTimeStamp
.SubtractWeeks(ANumber
: Cardinal);
1104 while ANumber
> MaxWeekAdd
do
1106 SubtractDays(MaxWeekAdd
* IdDaysInWeek
);
1107 Dec(ANumber
, MaxWeekAdd
* IdDaysInWeek
);
1109 SubtractDays(ANumber
* IdDaysInWeek
);
1112 procedure TIdDateTimeStamp
.SubtractYears
;
1114 if (FYear
> 0) and (ANumber
>= Cardinal(FYear
)) then
1119 FYear
:= FYear
- Integer(ANumber
);