Incomplete documentation of FormatDateTime
Original Reporter info from Mantis: wp @wpam
-
Reporter name:
Original Reporter info from Mantis: wp @wpam
- Reporter name:
Description:
The documentation of FormatDateTime states that the identfier "m" refers to "month" and "n" refers to "minute".
This is only partly correct: "m" can also be used in case of a time format if it is preceeded by an "h" specifier or if it is used within the ShortTimeFormat or LongTimeFormat of the FormatSettings.
In addition, the documentation does not mention the extended syntax with square brackets which has been added some time ago for displaying time intervals of more than 24 hours ([h], [hh]), more than 60 minutes ([m], [mm], [n], [nn]), or more than 60 seconds ([s], [ss]).
The documentation for FormatDateTime should be changed as follows:
m -- month, or minute if preceeded by an hour specifier (h, or hh), or if it is used in the ShortTimeFormat or LongTimeFormat of the FormatSettings.
mm -- month with leading zero, or minute with leading zero if preceeded by an hour specifier (h, or hh), or if it is used in the ShortTimeFormat or LongTimeFormat of the FormatSettings.
[h] -- hours including the hours of the full days (i.e. can be > 24). Only available if fdoInterval is specified in options argument to FormatDateTime. Use [hh] for displaying a leading zero.
[n] -- minutes including the minutes of the full hours and days, also: [nn] (or [m] or [mm] if in time part of the format string). Only available if fdoInterval is specified in options argument to FormatDateTime.
[s] -- seconds (including the seconds of the full minutes, hours and days, also: [ss]. Only available if fdoInterval is specified in options argument to FormatDateTime.
Steps to reproduce:
Run this demo to verify:
program Project1;
{$mode objfpc}{$H+}
uses
Classes, SysUtils, DateUtils;
var
t: TDateTime;
begin
t := encodeDate(2017, 2, 27) + EncodeTime(23,59,0,0);
WriteLn('The test date/time is ', DateToStr(t), ' ', TimeToStr(t));
WriteLn;
WriteLn('m PRECEEDED BY h --> MINUTES SHOULD BE ', MinuteOf(t));
WriteLn('hh:nn --- ',FormatDateTime('hh:nn', t));
WriteLn('hh:mm --- ', FormatDateTime('hh:mm', t));
WriteLn('hh.mm --- ', FormatDateTime('hh.mm', t));
WriteLn('hh-mm --- ', FormatDateTime('hh-mm', t));
WriteLn;
WriteLn('m NOT PRECEEDED BY h --> MINUTES SHOULD BE ', MonthOf(t));
WriteLn('mm:hh --- ', FormatDateTime('mm:hh', t));
WriteLn('mm:ss --- ', FormatDateTime('mm:ss', t));
WriteLn;
WriteLn('ORIGINAL FORMATSETTINGS --> MINUTES SHOULD BE ', MinuteOf(t));
WriteLn('c --- ', FormatDateTime('c', t));
WriteLn('t --- ', FormatDateTime('t', t));
WriteLn('tt --- ', FormatDateTime('tt', t));
WriteLn;
WriteLn('MODIFIED FORMATSETTINGS (h,m,s reversed) --> MINUTES SHOULD BE ', MinuteOf(t));
DefaultFormatSettings.ShortTimeFormat := 'mm:ss';
DefaultFormatSettings.LongTimeFormat := 'ss:mm:hh';
WriteLn('c --- ', FormatDateTime('c', t));
WriteLn('t --- ', FormatDateTime('t', t));
WriteLn('tt --- ', FormatDateTime('tt', t));
ReadLn;
end.
Mantis conversion info:
- Mantis ID: 31449
- Version: 3.1.1
- Fixed in version: 3.1.1
- Fixed in revision: 1402 (#f9b98e69),35892
- Target version: 3.2.0