Skip to content

Commit

Permalink
* [Calendar] GetDayFromYearBegin Supports Minute and Second.
Browse files Browse the repository at this point in the history
  • Loading branch information
Liu Xiao committed Sep 29, 2022
1 parent 75be4f8 commit 99273b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 7 additions & 5 deletions Source/Common/CnCalendar.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 表示不合法日期
Expand Down
10 changes: 8 additions & 2 deletions Source/Graphics/CnMemo.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 99273b4

Please sign in to comment.