View Issue Details

IDProjectCategoryView StatusLast Update
0038630FPCRTLpublic2021-03-19 12:46
ReporterLagunov Aleksey Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformFedoraOSLinux 
Product Version3.2.1 
Fixed in Version3.3.1 
Summary0038630: function NOW return time excluding time zone
Descriptionin OS set timezone +03
current time 11:00
NOW return 08:00

error only in Linux. On windows (test on windows7, wine) work normal.
TagsNo tags attached.
Fixed in Revision49006
FPCOldBugId
FPCTarget3.2.2
Attached Files

Relationships

has duplicate 0038586 resolvedMichael Van Canneyt Incorrect work with tzdata. 

Activities

Michael Van Canneyt

2021-03-16 10:57

administrator   ~0129706

Now works fine here, I am at GMT+1.

Please give more information about your setup:
- Available Environment variables when running the program.
- Output of strace -l log.txt yourprogram

Lagunov Aleksey

2021-03-16 11:15

reporter   ~0129707

test app:
uses sysutils;
var
  D: TDateTime;
begin
  D:=Now;
  writeln(DateTimeToStr(D));
end.

output:
$ ./aa
16-3-21 10:11:40
$ date
Вт 16 мар 2021 13:11:41 MSK

strace output:
execve("./aa", ["./aa"], 0x7ffc00609230 /* 68 vars */) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
rt_sigaction(SIGFPE, {sa_handler=0x4244c0, sa_mask=[], sa_flags=SA_RESTORER|SA_SIGINFO, sa_restorer=0x4012b0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGSEGV, {sa_handler=0x4244c0, sa_mask=[], sa_flags=SA_RESTORER|SA_SIGINFO, sa_restorer=0x4012b0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGBUS, {sa_handler=0x4244c0, sa_mask=[], sa_flags=SA_RESTORER|SA_SIGINFO, sa_restorer=0x4012b0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGILL, {sa_handler=0x4244c0, sa_mask=[], sa_flags=SA_RESTORER|SA_SIGINFO, sa_restorer=0x4012b0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x3), ...}) = 0
fstat(2, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x3), ...}) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x3), ...}) = 0
fstat(2, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x3), ...}) = 0
mmap(NULL, 32768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f067da88000
open("/etc/timezone", O_RDONLY|O_LARGEFILE) = -1 ENOENT (Нет такого файла или каталога)
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=1535, ...}) = 0
open("/etc/localtime", O_RDONLY|O_LARGEFILE) = 3
read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\21\0\0\0\21\0\0\0\0"..., 2048) = 1535
mmap(NULL, 262144, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f067da48000
mmap(NULL, 32768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f067da40000
mmap(NULL, 32768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f067da38000
mmap(NULL, 32768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f067da30000
close(3) = 0
time([1615889301 /* 2021-03-16T13:08:21+0300 */]) = 1615889301 (2021-03-16T13:08:21+0300)
gettimeofday({tv_sec=1615889301, tv_usec=573096}, NULL) = 0
time([1615889301 /* 2021-03-16T13:08:21+0300 */]) = 1615889301 (2021-03-16T13:08:21+0300)
time([1615889301 /* 2021-03-16T13:08:21+0300 */]) = 1615889301 (2021-03-16T13:08:21+0300)
write(1, "16-3-21 10:08:21\n", 17) = 17
munmap(0x7f067da30000, 32768) = 0
munmap(0x7f067da38000, 32768) = 0
munmap(0x7f067da40000, 32768) = 0
munmap(0x7f067da48000, 262144) = 0
munmap(0x7f067da88000, 32768) = 0
exit_group(0) = ?
+++ exited with 0 +++

fpc version:
$ fpc
Free Pascal Compiler version 3.3.1 [2021/03/16] for x86_64

fpc revision:
48990

Lagunov Aleksey

2021-03-16 11:19

reporter   ~0129708

on linux NOW use fpgettimeofday function

https://lazarus-ccr.sourceforge.io/docs/rtl/unix/fpgettimeofday.html

FpGetTimeOfDay returns the number of seconds since 00:00, January 1 1970, GMT in a timeval record. This time NOT corrected any way, not taking into account timezones, daylight savings time and so on.

Michael Van Canneyt

2021-03-16 11:30

administrator   ~0129709

But Now corrects the time for timezone using EpochToLocal
When I compile your program, it works correct:
home:~> fpc ttz.pp
home:~> ttz
16-3-21 11:25:35
home:~> date
Tue 16 Mar 11:25:41 CET 2021

Please change your program, so it prints the TZSeconds variable (which is what gets added to the output of fpgettimeofday):

uses sysutils, unixutil;
var
  D: TDateTime;
begin
  D:=Now;
  writeln(DateTimeToStr(D),' TZ Seconds: ',TZSeconds);
end.

home:~> ppcx64-3.2.0 ttz.pp
home:~> ttz
16-3-21 11:28:37 TZ Seconds: 3600

As you can see, it adds 1 hour for my case. What is the output in your case ?

Lagunov Aleksey

2021-03-16 13:47

reporter   ~0129710

property TZSeconds defined in module unix

im change source to:

uses sysutils, unix;
var
  D: TDateTime;
begin
  D:=Now;
  writeln(DateTimeToStr(D),' TZ Seconds: ',TZSeconds);
end.

result:
$ ./a2
16-3-21 12:47:05 TZ Seconds: 0

Michael Van Canneyt

2021-03-16 14:07

administrator   ~0129711

What version of fpc are you using, trunk ? Because in 3.2.x it is in unixutils.

So, the timezone is not detected correctly.
You will need to debug why this is happening.

Lagunov Aleksey

2021-03-16 14:10

reporter   ~0129712

Sory, I have incorrectly specified the version in the message header

$ fpc
Free Pascal Compiler version 3.3.1 [2021/03/16] for x86_64
from svn

DoctorS

2021-03-17 09:33

reporter   ~0129730

We have same problem on Linux (Ubuntu) with Now :( https://bugs.freepascal.org/view.php?id=38586

Michael Van Canneyt

2021-03-17 09:50

administrator   ~0129732

Can you please send me the TZ file that is actually read ? (attach to this bugreport or 38586)
You can get the name of this file with the output of strace.

If I do a strace, I see this:

open("/etc/timezone", O_RDONLY|O_LARGEFILE) = 3
read(3, "Europe/Brussels\n", 255) = 16
close(3) = 0
open("/usr/share/zoneinfo/Europe/Brussels", O_RDONLY|O_LARGEFILE) = 3
read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\v\0\0\0\v\0\0\0\0"..., 2048) = 2048

I want to have your file simply to be sure that I have a correct file to work with.

DoctorS

2021-03-17 10:06

reporter   ~0129734

Please, see: https://bugs.freepascal.org/view.php?id=38586

Lagunov Aleksey

2021-03-17 10:06

reporter   ~0129735

Last edited: 2021-03-17 10:09

View 2 revisions

used file /etc/localtime - symlink to /usr/share/zoneinfo/Europe/Moscow
file from tzdata-2021a-1.fc33.noarch
Moscow (1,535 bytes)   
TZif2N&��_ǝ>�y�*��9i��W���l�9��<�@�m��=2��h��=��EP��`'���@�P�����C@̓�����������s�|d� lU�!\F�"L7�#<(�$,�%
�&��''p'�p(��)x��)�p*��p+��p,��p-��p.��p/t�p0d�p1]��2r��3=��4Ry�5��62[�6�b�8xp8�D�9�Zp:�&�;�<p<�Cp=�p>�%p?�p@fpA��BE�pCc��D%�pEC��F�pG#��G���I��IΫ�J��K���ḶpM�o�TL`	



























#9#91�#w?�8@*08@FP *08@*0! 8@8@*0LMTMMTMSTMDSTMSDMSK+05EETEESTTZif2N&����V�������_�����>�y�����*������9i������W�������l����9������<�@�����m������=2������h������=������EP������`'���@�P�����C@̓�����������s�|d� lU�!\F�"L7�#<(�$,�%
�&��''p'�p(��)x��)�p*��p+��p,��p-��p.��p/t�p0d�p1]��2r��3=��4Ry�5��62[�6�b�8xp8�D�9�Zp:�&�;�<p<�Cp=�p>�%p?�p@fpA��BE�pCc��D%�pEC��F�pG#��G���I��IΫ�J��K���ḶpM�o�TL`	



























#9#91�#w?�8@*08@FP *08@*0! 8@8@*0LMTMMTMSTMDSTMSDMSK+05EETEEST
MSK-3
Moscow (1,535 bytes)   

Michael Van Canneyt

2021-03-17 10:09

administrator   ~0129736

Thank you. I will look at this.

Michael Van Canneyt

2021-03-19 10:23

administrator   ~0129756

Fixed. Ondrej Pokorny also fixed part of the problem.

Thanks for reporting!

Issue History

Date Modified Username Field Change
2021-03-16 10:19 Lagunov Aleksey New Issue
2021-03-16 10:57 Michael Van Canneyt Note Added: 0129706
2021-03-16 11:15 Lagunov Aleksey Note Added: 0129707
2021-03-16 11:19 Lagunov Aleksey Note Added: 0129708
2021-03-16 11:30 Michael Van Canneyt Note Added: 0129709
2021-03-16 13:47 Lagunov Aleksey Note Added: 0129710
2021-03-16 14:07 Michael Van Canneyt Note Added: 0129711
2021-03-16 14:10 Lagunov Aleksey Note Added: 0129712
2021-03-17 09:33 DoctorS Note Added: 0129730
2021-03-17 09:45 Michael Van Canneyt Relationship added has duplicate 0038586
2021-03-17 09:50 Michael Van Canneyt Assigned To => Michael Van Canneyt
2021-03-17 09:50 Michael Van Canneyt Status new => feedback
2021-03-17 09:50 Michael Van Canneyt FPCTarget => -
2021-03-17 09:50 Michael Van Canneyt Note Added: 0129732
2021-03-17 10:06 DoctorS Note Added: 0129734
2021-03-17 10:06 Lagunov Aleksey Note Added: 0129735
2021-03-17 10:06 Lagunov Aleksey File Added: Moscow
2021-03-17 10:06 Lagunov Aleksey Status feedback => assigned
2021-03-17 10:09 Michael Van Canneyt Note Added: 0129736
2021-03-17 10:09 Lagunov Aleksey Note Edited: 0129735 View Revisions
2021-03-19 10:23 Michael Van Canneyt Status assigned => resolved
2021-03-19 10:23 Michael Van Canneyt Resolution open => fixed
2021-03-19 10:23 Michael Van Canneyt Fixed in Version => 3.3.1
2021-03-19 10:23 Michael Van Canneyt Fixed in Revision => 49006
2021-03-19 10:23 Michael Van Canneyt FPCTarget - => 3.2.2
2021-03-19 10:23 Michael Van Canneyt Note Added: 0129756
2021-03-19 12:46 Lagunov Aleksey Status resolved => closed