View Issue Details

IDProjectCategoryView StatusLast Update
0031449FPCDocumentationpublic2017-04-22 16:31
ReporterwpAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.1.1Product Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0031449: Incomplete documentation of FormatDateTime
DescriptionThe 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 ReproduceRun 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.
TagsNo tags attached.
Fixed in Revision1402,35892
FPCOldBugId
FPCTarget
Attached Files
  • datih.inc.patch (631 bytes)
    Index: rtl/objpas/sysutils/datih.inc
    ===================================================================
    --- rtl/objpas/sysutils/datih.inc	(revision 35654)
    +++ rtl/objpas/sysutils/datih.inc	(working copy)
    @@ -57,8 +57,8 @@
           dddd   : day of week (full)
           ddddd  : shortdateformat
           dddddd : longdateformat
    -      m      : month
    -      mm     : month (leading zero)
    +      m      : month or minute if preceded by h or hh specifiers
    +      mm     : month or minute if preceded by h or hh specifiers(leading zero)
           mmm    : month (abbreviation)
           mmmm   : month (full)
           y      : year (two digits)
    
    datih.inc.patch (631 bytes)

Relationships

has duplicate 0031448 resolvedMichael Van Canneyt "mm" vs "nn" not sufficiently documented vs preceding "hh" 

Activities

Thaddy de Koning

2017-02-27 12:23

reporter   ~0098492

Duplicate of previous, but with much better explanation.

Michael Van Canneyt

2017-03-04 15:18

administrator   ~0098626

Changed the documentation to mention the [] forms, and mm->nn switch if preceded by hh/mm

wp

2017-03-24 23:30

reporter   ~0099210

There is documentation of the FormatDateTime parameters also in datih.inc. Probably it should be updated as well - see patch.

wp

2017-03-24 23:31

reporter  

datih.inc.patch (631 bytes)
Index: rtl/objpas/sysutils/datih.inc
===================================================================
--- rtl/objpas/sysutils/datih.inc	(revision 35654)
+++ rtl/objpas/sysutils/datih.inc	(working copy)
@@ -57,8 +57,8 @@
       dddd   : day of week (full)
       ddddd  : shortdateformat
       dddddd : longdateformat
-      m      : month
-      mm     : month (leading zero)
+      m      : month or minute if preceded by h or hh specifiers
+      mm     : month or minute if preceded by h or hh specifiers(leading zero)
       mmm    : month (abbreviation)
       mmmm   : month (full)
       y      : year (two digits)
datih.inc.patch (631 bytes)

Bart Broersma

2017-03-26 20:28

reporter   ~0099239

> month or minute if preceded by h or hh specifiers
Sounds a bit ambiguous to me.

wp

2017-03-26 21:53

reporter   ~0099242

The "if" refers to "minute", not to the combined "month or minute": Normally the "m" means "month", but if it is preceeded by an "h" or "hh" it is interpreted as "minute".

Is it clearer with a comma after "month": "month, or minute if preceded by h or hh specifiers" ?

Bart Broersma

2017-03-27 00:04

reporter   ~0099244

Maybe:
"if preceded by h or hh speciefiers: minute, otherwise month"

Note that English is not my native language.

Michael Van Canneyt

2017-04-22 12:03

administrator   ~0099762

Fixed. In future, please create a separate bugreport.

wp

2017-04-22 16:31

reporter   ~0099782

Thank you. And sorry for pulling this up again in the same report...

Issue History

Date Modified Username Field Change
2017-02-27 11:53 wp New Issue
2017-02-27 11:53 wp Status new => assigned
2017-02-27 11:53 wp Assigned To => Michael Van Canneyt
2017-02-27 12:23 Thaddy de Koning Note Added: 0098492
2017-03-04 15:18 Michael Van Canneyt Fixed in Revision => 1402
2017-03-04 15:18 Michael Van Canneyt Note Added: 0098626
2017-03-04 15:18 Michael Van Canneyt Status assigned => resolved
2017-03-04 15:18 Michael Van Canneyt Fixed in Version => 3.1.1
2017-03-04 15:18 Michael Van Canneyt Resolution open => fixed
2017-03-04 15:18 Michael Van Canneyt Target Version => 3.2.0
2017-03-04 15:19 Michael Van Canneyt Relationship added has duplicate 0031448
2017-03-24 23:30 wp Note Added: 0099210
2017-03-24 23:30 wp Status resolved => feedback
2017-03-24 23:30 wp Resolution fixed => reopened
2017-03-24 23:31 wp File Added: datih.inc.patch
2017-03-26 20:28 Bart Broersma Note Added: 0099239
2017-03-26 21:53 wp Note Added: 0099242
2017-03-26 21:53 wp Status feedback => assigned
2017-03-27 00:04 Bart Broersma Note Added: 0099244
2017-04-22 12:03 Michael Van Canneyt Fixed in Revision 1402 => 1402,35892
2017-04-22 12:03 Michael Van Canneyt Note Added: 0099762
2017-04-22 12:03 Michael Van Canneyt Status assigned => resolved
2017-04-22 12:03 Michael Van Canneyt Resolution reopened => fixed
2017-04-22 16:31 wp Note Added: 0099782
2017-04-22 16:31 wp Status resolved => closed