View Issue Details

IDProjectCategoryView StatusLast Update
0030697FPCRTLpublic2016-11-27 22:11
ReporterThaddy de KoningAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformAllOSOS Version
Product Version3.1.1Product Build34613 
Target Version3.2.0Fixed in Version3.1.1 
Summary0030697: Unix time conversion routines one second off
DescriptionUnixToDateTime and DateTimeToUnix render a one second difference.
Steps To Reproduceuses sysutils,dateutils;
var
   fec: TDateTime;
   n: LongInt;
begin
   fec := now;
   n := DateTimeToUnix(fec);
   writeln(DateTimeToStr(fec), '=', n);
   fec := UnixToDateTime(n);
   writeln(DateTimeToStr(fec), '=', n);
   writeln('');
end.
----
 sampleoutput:
5-10-16 06:29:25=1475648966
..............^v...........
5-10-16 06:29:26=1475648966
 
Additional InformationI don't know which one is wrong.
TagsNo tags attached.
Fixed in Revision34997
FPCOldBugId
FPCTarget
Attached Files

Relationships

related to 0012894 closedJonas Maebe DateTimeToUnix rounding error 

Activities

Thaddy de Koning

2016-10-05 09:32

reporter   ~0094963

Last edited: 2016-10-05 12:27

View 2 revisions

Since there is rounding/truncating the results should be equal by definition.
See valuable discussion here:
http://forum.lazarus.freepascal.org/index.php?action=post;topic=34294.0;last_msg=224304

Michael Van Canneyt

2016-11-27 14:10

administrator   ~0096299

First of all, it's not always 1 second off: my first test showed:

home: ~/fpc/packages/rtl-objpas/src/inc >./testd
27-11-16 14:00:57=1480255257
27-11-16 14:00:57=1480255257

But indeed, it's sometimes 1 second off.
I checked the implementation, and instead of round, trunc must be used.

Your comment about 'being the same by definition' is somewhat confusing, since the use of round/trunc IMO exactly implies that there can be a difference.

Anyway, fixed, thanks for the report.

Jonas Maebe

2016-11-27 19:01

manager   ~0096309

This change breaks webtbs/tw12894.pp and no new test was added.

Michael Van Canneyt

2016-11-27 20:56

administrator   ~0096311

Problem was in milliseconds being taken into account.
Properly fixed by removing milliseconds.

Test added to private testsuite.

Florian

2016-11-27 21:03

administrator   ~0096312

No chance for a regression test in fpc/tests :)?

Jonas Maebe

2016-11-27 22:11

manager   ~0096318

Could you at least create a new, public svn repository with your private tests? That way, should your hard drive crash or so, all of those tests won't simply be gone. At the same time, other people could start adding those tests to the testsuite so they become useful to everyone.

Issue History

Date Modified Username Field Change
2016-10-05 06:40 Thaddy de Koning New Issue
2016-10-05 09:32 Thaddy de Koning Note Added: 0094963
2016-10-05 12:27 Thaddy de Koning Note Edited: 0094963 View Revisions
2016-11-27 14:10 Michael Van Canneyt Fixed in Revision => 34983
2016-11-27 14:10 Michael Van Canneyt Note Added: 0096299
2016-11-27 14:10 Michael Van Canneyt Status new => resolved
2016-11-27 14:10 Michael Van Canneyt Fixed in Version => 3.1.1
2016-11-27 14:10 Michael Van Canneyt Resolution open => fixed
2016-11-27 14:10 Michael Van Canneyt Assigned To => Michael Van Canneyt
2016-11-27 14:10 Michael Van Canneyt Target Version => 3.2.0
2016-11-27 19:01 Jonas Maebe Note Added: 0096309
2016-11-27 19:01 Jonas Maebe Status resolved => assigned
2016-11-27 19:03 Jonas Maebe Relationship added related to 0012894
2016-11-27 20:56 Michael Van Canneyt Fixed in Revision 34983 => 34997
2016-11-27 20:56 Michael Van Canneyt Note Added: 0096311
2016-11-27 20:56 Michael Van Canneyt Status assigned => resolved
2016-11-27 21:03 Florian Note Added: 0096312
2016-11-27 22:11 Jonas Maebe Note Added: 0096318