From 99273b4245c5c6a793786553da033755f65898ba Mon Sep 17 00:00:00 2001 From: Liu Xiao Date: Thu, 29 Sep 2022 17:55:05 +0800 Subject: [PATCH] * [Calendar] GetDayFromYearBegin Supports Minute and Second. --- Source/Common/CnCalendar.pas | 12 +++++++----- Source/Graphics/CnMemo.pas | 10 ++++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Source/Common/CnCalendar.pas b/Source/Common/CnCalendar.pas index f43ba6d19..6e95484a6 100644 --- a/Source/Common/CnCalendar.pas +++ b/Source/Common/CnCalendar.pas @@ -329,8 +329,9 @@ function GetIsLeapYear(AYear: Integer): Boolean; function GetDayFromYearBegin(AYear, AMonth, ADay: Integer): Integer; overload; {* 取某日期到年初的天数,不考虑 1582 年 10 月的特殊情况 } -function GetDayFromYearBegin(AYear, AMonth, ADay, AHour: Integer): Extended; overload; -{* 取某日期到年初的天数,小时数折算入小数,不考虑 1582 年 10 月的特殊情况 } +function GetDayFromYearBegin(AYear, AMonth, ADay, AHour: Integer; + AMinute: Integer = 0; ASecond: Integer = 0): Extended; overload; +{* 取某日期到年初的天数,小时、分、秒数折算入小数,不考虑 1582 年 10 月的特殊情况 } function ExtractMonthDay(Days: Integer; AYear: Integer; out AMonth: Integer; out ADay: Integer): Boolean; @@ -1833,11 +1834,12 @@ function GetDayFromYearBegin(AYear, AMonth, ADay: Integer): Integer; Result := MonthAbsDays[GetIsLeapYear(AYear)][AMonth] + ADay; end; -// 取某日期到年初的天数,小时数折算入小数,不考虑 1582 年 10 月的特殊情况 -function GetDayFromYearBegin(AYear, AMonth, ADay, AHour: Integer): Extended; +// 取某日期到年初的天数,小时、分、秒数折算入小数,不考虑 1582 年 10 月的特殊情况 +function GetDayFromYearBegin(AYear, AMonth, ADay, AHour: Integer; + AMinute, ASecond: Integer): Extended; begin Result := GetDayFromYearBegin(AYear, AMonth, ADay); - Result := Result + (AHour / 24.0); + Result := Result + (AHour / 24.0) + (AMinute / 1440.0) + (ASecond / 86400.0); end; // 从距年首天数返回月和日数,年份用来判断是否是闰年,返回 False 表示不合法日期 diff --git a/Source/Graphics/CnMemo.pas b/Source/Graphics/CnMemo.pas index 3d3aefbe9..238d99347 100644 --- a/Source/Graphics/CnMemo.pas +++ b/Source/Graphics/CnMemo.pas @@ -679,10 +679,13 @@ function GetColumnWidthFromWideString(const S: TCnEditorString): Integer; function TCnStringsControl.CalcColumnFromPixelOffsetInLine(ARow, VirtualX: Integer; out Col: Integer; out LeftHalf, DoubleWidth: Boolean): Boolean; var - I, L, X, OldX, W2, T: Integer; + I, L, X, OldX, W2: Integer; W, DirectCalc: Boolean; S: string; +{$IFNDEF UNICODE} + T: Integer; SW: WideString; +{$ENDIF} C: WideChar; Size: TSize; begin @@ -786,9 +789,12 @@ function TCnStringsControl.CalcPixelOffsetFromColumnInLine(ARow, ACol: Integer; out Rect: TRect; out DoubleWidth: Boolean): Boolean; var W, DirectCalc: Boolean; - I, W2, X, OldX, Col, OldCol, T, L: Integer; + I, W2, X, OldX, Col, OldCol, L: Integer; S: string; +{$IFNDEF UNICODE} + T: Integer; SW: WideString; +{$ENDIF} C: WideChar; Size: TSize; begin