Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] dateTime.hour(date) is off by one hour #159

Open
kseistrup opened this issue Jul 13, 2024 · 5 comments
Open

[C++] dateTime.hour(date) is off by one hour #159

kseistrup opened this issue Jul 13, 2024 · 5 comments

Comments

@kseistrup
Copy link

In the following I expected dateTime.hour(now) to return 16, instead I got 17:

» miniscript
MiniScript 
Command-Line (Linux) v1.3; language v1.6.2 (Jul 13 2024)
> import "dateTime"
> now = dateTime.now
> now
2024-07-13 16:51:19
> dateTime.hour(now)
17
@kseistrup
Copy link
Author

Oh, dateTime.hour() expects a .nowVal, not a .now

@marcgurevitx
Copy link
Contributor

.hour() calls _dateStr() which should handle both of those...

@kseistrup : Is your area affected by "daylight savings"? If so, maybe this issue should be reopened.

@kseistrup
Copy link
Author

kseistrup commented Jul 13, 2024

@marcgurevitx

Is your area affected by "daylight savings"?

Yes, I'm in Europe/Copenhagen: currently CEST (UTC+2), normally CET (UTC+1).

I am completely new to miniscript (after it was mentioned on lobste.rs) and wrote a short script in miniscript:

https://codeberg.org/kas/qtime/src/branch/master/miniscript/qtime.ms

It works with .nowVal, but not with .now. I will reopen this issue then.


edit: typo

@kseistrup kseistrup reopened this Jul 13, 2024
@kseistrup kseistrup changed the title dateTime.hour(date) is off by one hour [C++] dateTime.hour(date) is off by one hour Jul 13, 2024
@marcgurevitx
Copy link
Contributor

@kseistrup Can you edit the source and add

dateTime.tm_isdst = -1;

right before this call to mktime() in DateTimeUtils.cpp, line 307 ?

It fixes the issue on my machine when I "pretend" that I'm in Copenhagen. Want to be sure that for the real Copenhagen it works as well.

@kseistrup
Copy link
Author

@marcgurevitx

After adding that line dateTime.hour(date) gives the right answer both when date is a .now and a .nowVal.

Using faketime, it also seems to work for dates when Denmark has switched back to normal time. This goes well with what mktime(3) says abouit the tm_isdst field, but I'm unsure how reliable results obtained with faketime is in this context.

For now the addition seems to have solved the issue.

Thanks 🙏

archlinux-github pushed a commit to archlinux/aur that referenced this issue Jul 15, 2024
marcgurevitx added a commit to marcgurevitx/miniscript-by-jjs that referenced this issue Jul 15, 2024
borgi pushed a commit to borgi/csucsu_miniscript that referenced this issue Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants