Hallo,
I have a python-script which is called at 0 and 30 minutes at every hour
from a cronjob:
0,30 * * * * sudo python3 /*****
In the script I call the current time:
akdatum = datetime.datetime.today()
akzeit = akdatum.time()
akzeitstr = akzeit.strftime('%H:%M')
At 0 minutes the returned hour is one hour BEFORE the real hour.
At 30 minutes the returned hour is the correct hour.
Any ideas ?
I have a python-script which is called at 0 and 30 minutes at every hour
from a cronjob:
0,30 * * * * sudo python3 /*****
In the script I call the current time:
akdatum = datetime.datetime.today()
akzeit = akdatum.time()
akzeitstr = akzeit.strftime('%H:%M')
At 0 minutes the returned hour is one hour BEFORE the real hour.
At 30 minutes the returned hour is the correct hour.
Any ideas ?
Provide a bit more info
Hallo,
I have a python-script which is called at 0 and 30 minutes at every hour
from a cronjob:
0,30 * * * * sudo python3 /*****
In the script I call the current time:
akdatum = datetime.datetime.today()
akzeit = akdatum.time()
akzeitstr = akzeit.strftime('%H:%M')
At 0 minutes the returned hour is one hour BEFORE the real hour.
At 30 minutes the returned hour is the correct hour.
Any ideas ?
On Sat, 17 Jun 2023 16:53:23 +0200, Dietmar Mysliwietz wrote:
Hallo,
I have a python-script which is called at 0 and 30 minutes at every hour
from a cronjob:
0,30 * * * * sudo python3 /*****
In the script I call the current time:
akdatum = datetime.datetime.today()
akzeit = akdatum.time()
akzeitstr = akzeit.strftime('%H:%M')
At 0 minutes the returned hour is one hour BEFORE the real hour.
At 30 minutes the returned hour is the correct hour.
Any ideas ?
I don't know python, so I can't answer why the on-the-half-hour
executions get the proper time, but the on-the-hour time
discrepancy sounds like a time-zone "summer time" problem.
AIUT, Germany (or at least, parts of Germany) are now on
"summer time", where the wall-clock time is one hour ahead
of the "standard time" clock. It sounds like, for your
on-the-hour execution, you are picking up "standard time"
rather than "summer time".
I note that, from the python documentation at
https://docs.python.org/3/library/datetime.html,
datetime.datetime.today() will "Return the current local
datetime, with tzinfo None." As I said, I don't know
python, so I don't know the impact of "tzinfo None". But...
as "summer time" offsets are usually part of the tzinfo,
perhaps this "tzinfo None" is interfering with your
"summer time" time conversion.
Just a guess. Hope this helps you find the problem.
Dietmar,
"R.Wieser" <address@is.invalid> wrote in message news:u6mbsm$1jqm6$1@dont-email.me...
...
Provide a bit more info
You know, I currently do not even know what you are using that code of yours for (creating a time-stamped file ?) and/or how you determined that the hour is (sometimes) wrong.
There is a chance you're misunderstanding what you are seeing, or looking at the wrong output. But with the rather meager info you supplied there is no way for us to figure any such thing out.
Which might well be why you have so few responses ...
Regards,
Rudy Wieser
Am 18.06.2023 um 11:22 schrieb R.Wieser:
Dietmar,
"R.Wieser" <address@is.invalid> wrote in message
news:u6mbsm$1jqm6$1@dont-email.me...
...
Provide a bit more info
You know, I currently do not even know what you are using that code of
yours
for (creating a time-stamped file ?) and/or how you determined that
the hour
is (sometimes) wrong.
There is a chance you're misunderstanding what you are seeing, or
looking at
the wrong output. But with the rather meager info you supplied there
is no
way for us to figure any such thing out.
Which might well be why you have so few responses ...
Regards,
Rudy Wieser
Thank you Rudy,
what I tried was, to wait a few seconds in the Python-script: no success.
And I wrote in the Python-script the time values to a file. There are
the wrong hours too. But the file has the correct timestamp. The RPi has timezone information (Europe/Berlin).
Now I try timezone information in the Python.
Dietmar.
On 18/06/2023 12:58, Dietmar Mysliwietz wrote:
Am 18.06.2023 um 11:22 schrieb R.Wieser:It wouldn't be the first time a language-supplied library had some kind
Dietmar,
"R.Wieser" <address@is.invalid> wrote in message
news:u6mbsm$1jqm6$1@dont-email.me...
...
Provide a bit more info
You know, I currently do not even know what you are using that code
of yours
for (creating a time-stamped file ?) and/or how you determined that
the hour
is (sometimes) wrong.
There is a chance you're misunderstanding what you are seeing, or
looking at
the wrong output. But with the rather meager info you supplied there
is no
way for us to figure any such thing out.
Which might well be why you have so few responses ...
Regards,
Rudy Wieser
Thank you Rudy,
what I tried was, to wait a few seconds in the Python-script: no success.
And I wrote in the Python-script the time values to a file. There are
the wrong hours too. But the file has the correct timestamp. The RPi
has timezone information (Europe/Berlin).
of bug in it.
Not a great Python coder, but can you essentially execute the Linux
'date' command and parse the output?
I have to say I've used date time functions in 'C' and never had an issue.
Now I try timezone information in the Python.
Dietmar.
Dietmar Mysliwietz <dmysliwietz@web.de> schrieb:
Hallo,Yeah, just an idea. Try in crontab
I have a python-script which is called at 0 and 30 minutes at every hour
from a cronjob:
0,30 * * * * sudo python3 /*****
In the script I call the current time:
akdatum = datetime.datetime.today()
akzeit = akdatum.time()
akzeitstr = akzeit.strftime('%H:%M')
At 0 minutes the returned hour is one hour BEFORE the real hour.
At 30 minutes the returned hour is the correct hour.
Any ideas ?
0,30 * * * * sudo { sleep 1; python3 /*****; } (or so)
Thank you.
Dietmar.
Hallo,
I have a python-script which is called at 0 and 30 minutes at every hour
from a cronjob:
0,30 * * * * sudo python3 /*****
In the script I call the current time:
akdatum = datetime.datetime.today()
akzeit = akdatum.time()
akzeitstr = akzeit.strftime('%H:%M')
At 0 minutes the returned hour is one hour BEFORE the real hour.
At 30 minutes the returned hour is the correct hour.
Any ideas ?
Thank you.
Dietmar.
I wrote some Phyton-lines:
datum = datetime.datetime.now()
datum2 = datetime.datetime.now(pytz.timezone('Europe/Berlin'))
.. and called this script via cronjob at 0,30 * * * *
This script returne the correct time, my 'old big' script didn't.
Thank you Rudy,
what I tried was, to wait a few seconds in the Python-script: no success.
And I wrote in the Python-script the time values to a file. There are
the wrong hours too. But the file has the correct timestamp. The RPi has timezone information (Europe/Berlin).
Now I try timezone information in the Python.
Dietmar.
I don't think that there is a bug in the library.
Where the problem is .. getting crazy
The date at the commandline returnes the correct time.
It looks like the different accounts (users) can have their own timezones.
This has been a standard feature of unix since timezone support
first appeared.
It was not uncommon for multi-user systems with remote access to
have users in multiple timezones who naturally want to see their
own local time and not that of the machine room.
Am 18.06.2023 um 16:23 schrieb Michael Schütz:
Dietmar Mysliwietz <dmysliwietz@web.de> schrieb:
Hallo,Yeah, just an idea. Try in crontab
I have a python-script which is called at 0 and 30 minutes at every hour >>> from a cronjob:
0,30 * * * * sudo python3 /*****
In the script I call the current time:
akdatum = datetime.datetime.today()
akzeit = akdatum.time()
akzeitstr = akzeit.strftime('%H:%M')
At 0 minutes the returned hour is one hour BEFORE the real hour.
At 30 minutes the returned hour is the correct hour.
Any ideas ?
0,30 * * * * sudo { sleep 1; python3 /*****; } (or so)
Thank you.
Dietmar.
Thank you Michael,
that doesn't help. There was a time delay from 10 seconds in the Python
at the begin.
Am 18.06.2023 um 20:10 schrieb R.Wieser:
Ahem,
This has been a standard feature of unix since timezone support
first appeared.
Thanks for the confirmation.
And it shows how little I actually know about Linux.
It was not uncommon for multi-user systems with remote access to
have users in multiple timezones who naturally want to see their
own local time and not that of the machine room.
I already figured that that would be the logic behind having it. :-)
Regards,
Rudy Wieser
Thanks again Rudy,
I will tray to figure it out tomorrow.
Thanks a lot to all others.
Perhaps I code at a different level but I have found several bugs in PHP and/or javascript implementations.
Right at the edges of what is defined by the language
There is usually a workaround to avoid the case...
Dietmar,
I don't think that there is a bug in the library.
Thats a good thought, as problems are seldom caused by bugs. More often its just a simple misunderstanding something.
A prime example of that is how pure HTML webpages (no CSS or JS) display different in the different browsers
A prime example of that is how pure HTML webpages (no CSS or JS) display
different in the different browsers
just leaving the layout to the browser as originally intended and *only* providing semantic(ish) markup That was the original intention with HTML
JavaScript seemed like a good idea originally - it has got well out
of hand - DOM interaction was a *BAD* idea.
On Mon, 19 Jun 2023 11:17:10 +0200
"R.Wieser" <address@is.invalid> wrote:
A prime example of that is how pure HTML webpages (no CSS or JS) display
different in the different browsers
That was the original intention with HTML and if the advertisers
who insisted on being able to have pixel for pixel matches to their
designs
and been told to get stuffed from the beginning we might have escaped the chaos of CSS and the difficulties of designing for multiple device types
by
just leaving the layout to the browser as originally intended and *only* providing semantic(ish) markup.
JavaScript seemed like a good idea originally - it has got well out
of hand - DOM interaction was a *BAD* idea.
--
Steve O'Hara-Smith
Odds and Ends at http://www.sohara.org/
Host: Beautiful Theory meet Inconvenient Fact
Obit: Beautiful Theory died today of factual inconsistency
Am 18.06.2023 um 14:21 schrieb The Natural Philosopher:
On 18/06/2023 12:58, Dietmar Mysliwietz wrote:
Am 18.06.2023 um 11:22 schrieb R.Wieser:It wouldn't be the first time a language-supplied library had some
Dietmar,
"R.Wieser" <address@is.invalid> wrote in message
news:u6mbsm$1jqm6$1@dont-email.me...
...
Provide a bit more info
You know, I currently do not even know what you are using that code
of yours
for (creating a time-stamped file ?) and/or how you determined that
the hour
is (sometimes) wrong.
There is a chance you're misunderstanding what you are seeing, or
looking at
the wrong output. But with the rather meager info you supplied
there is no
way for us to figure any such thing out.
Which might well be why you have so few responses ...
Regards,
Rudy Wieser
Thank you Rudy,
what I tried was, to wait a few seconds in the Python-script: no
success.
And I wrote in the Python-script the time values to a file. There are
the wrong hours too. But the file has the correct timestamp. The RPi
has timezone information (Europe/Berlin).
kind of bug in it.
Not a great Python coder, but can you essentially execute the Linux
'date' command and parse the output?
I have to say I've used date time functions in 'C' and never had an
issue.
Now I try timezone information in the Python.
Dietmar.
I don't think that there is a bug in the library. Where the problem is
.. getting crazy
The date at the commandline returnes the correct time.
Dietmar.
I don't think that there is a bug in the library. Where the problem is
.. getting crazy
The date at the commandline returnes the correct time.
Dietmar.
On 18/06/2023 16:00, Dietmar Mysliwietz wrote:
I don't think that there is a bug in the library. Where the problem is
.. getting crazy
The date at the commandline returnes the correct time.
Dietmar.
I had a quick look and couldn't see where, or how, the value of datetime.today() becomes aware of timezone. There is some twaddle about "aware" and "naive" but I lost the will to live after seeing
"unambiguously".
As far as I can see, the only safe thing to do is to explicitly set the datetime tzinfo attribute. All in all, it looks like poo, not uncommon
for datetime libraries.
Caveat, I'm not a python programmer.
On 19/06/2023 14:23, Pancho wrote:
On 18/06/2023 16:00, Dietmar Mysliwietz wrote:
I don't think that there is a bug in the library. Where the problem
is .. getting crazy
The date at the commandline returnes the correct time.
Dietmar.
I had a quick look and couldn't see where, or how, the value of
datetime.today() becomes aware of timezone. There is some twaddle
about "aware" and "naive" but I lost the will to live after seeing
"unambiguously".
As far as I can see, the only safe thing to do is to explicitly set
the datetime tzinfo attribute. All in all, it looks like poo, not
uncommon for datetime libraries.
Caveat, I'm not a python programmer.
So following your example (I use utc, you can use whatever you like)
akziet = datetime.datetime.now(datetime.timezone.utc)
akzeitstr = akdatum.strftime('%H:%M %Z')
As far as I can see, the only safe thing to do is to explicitly set the datetime tzinfo attribute. All in all, it looks like poo, not uncommon
for datetime libraries.
You can still take two different browsers (read: HTML engines) and set
their widths to exactly the same, and you still stand a good chance that
a simple HTML-only document won't look the same on both.
Personally I've got JS permanently disabled. Because I've been taught
that running programs from unknown sources is never a good idea.
On Mon, 19 Jun 2023 14:23:45 +0100
Pancho <Pancho.Jones@proton.me> wrote:
As far as I can see, the only safe thing to do is to explicitly set the
datetime tzinfo attribute. All in all, it looks like poo, not uncommon
for datetime libraries.
If you don't set it explicitly then python will pick up a default
which can come from the TZ environment variable or if that is not set then
it should be the system default timezone. This applies to all date related functions not just python datetime viz:
✓ steve@steve ~ $ TZ=GMT date
Mon 19 Jun 2023 13:53:52 GMT
✓ steve@steve ~ $ TZ="Europe/Paris" date
Mon 19 Jun 2023 15:54:11 CEST
✓ steve@steve ~ $ date
Mon 19 Jun 2023 14:54:50 IST
15:16print( datetime.datetime.today().time().strftime('%H:%M %Z') )
15:16print( datetime.datetime.now().strftime('%H:%M %Z') )
%Z') )print( datetime.datetime.now(datetime.timezone.utc).strftime('%H:%M
Yes, the first two are in my localtime, BST, but Python is giving it as
a “naive” time, it isn't using a timezone. The third one does is recognizing timezone.
17:15import datetime
print( datetime.datetime.now().strftime('%H:%M %Z') )
✓ steve@steve ~ $ TZ="America/Los_Angeles" python3
09:15import datetime
print( datetime.datetime.now().strftime('%H:%M %Z') )
Of course HTML does not define what the appearance (if any) of
the rendered output looks like.
Personally I've got JS permanently disabled. Because I've been taught
that running programs from unknown sources is never a good idea.
There is much to be said for this approach - my own browser is set
up that way but for work there are too many cases where the browser is
mostly a UI server for applications - a perfectly valid and useful thing
in
itself but it's a shame that it wound up incorporated into the web
browser.
TNP,
Perhaps I code at a different level but I have found several bugs in PHP
and/or javascript implementations.
Not the same languages, but the same here. The most recent one not even a week old. It doesn't make any difference to my statement.
In practice most "bugs" turn out to be a misunderstanding (of what gets returned as a result of executing something). Assuming that everything
must be a bug of some sort is therefore quite counter productive.
And I did wonder how you could come up with a "work around" without even having an idea of what the problem was. Depending on luck perhaps ?
Alas, it didn't work this time. :-)
Right at the edges of what is defined by the language
Yep. A vague definition leaving it up to the implementer to make sense of
it often does that. Have multiple seperate parties make their own guesses towards such a vague definition and you're in for a ball.
A prime example of that is how pure HTML webpages (no CSS or JS) display different in the different browsers (and why some websites still display "best viewed in ..." banners).
There is usually a workaround to avoid the case...
There is seldom only one way to solve a problem.
Regards,
Rudy Wieser
On Mon, 19 Jun 2023 11:17:10 +0200
"R.Wieser" <address@is.invalid> wrote:
A prime example of that is how pure HTML webpages (no CSS or JS) display
different in the different browsers
That was the original intention with HTML and if the advertisers
who insisted on being able to have pixel for pixel matches to their designs and been told to get stuffed from the beginning we might have escaped the chaos of CSS and the difficulties of designing for multiple device types by just leaving the layout to the browser as originally intended and *only* providing semantic(ish) markup.
JavaScript seemed like a good idea originally - it has got well out
of hand - DOM interaction was a *BAD* idea.
Which could easily be the "fringe cases" TNP was referring to as "bugs".
Or, said simpler : those "fringe cases" probably work without any problem within the browser it was created for, but its output could mismatch that of another browser.
On 19/06/2023 14:39, Pancho wrote:
On 19/06/2023 14:23, Pancho wrote:
On 18/06/2023 16:00, Dietmar Mysliwietz wrote:
I don't think that there is a bug in the library. Where the problem
is .. getting crazy
The date at the commandline returnes the correct time.
Dietmar.
I had a quick look and couldn't see where, or how, the value of
datetime.today() becomes aware of timezone. There is some twaddle
about "aware" and "naive" but I lost the will to live after seeing
"unambiguously".
As far as I can see, the only safe thing to do is to explicitly set
the datetime tzinfo attribute. All in all, it looks like poo, not
uncommon for datetime libraries.
Caveat, I'm not a python programmer.
So following your example (I use utc, you can use whatever you like)
akziet = datetime.datetime.now(datetime.timezone.utc)
akzeitstr = akdatum.strftime('%H:%M %Z')
Or even
akziet = datetime.datetime.now(datetime.timezone.utc)
akzeitstr = akziet.strftime('%H:%M %Z')
On Mon, 19 Jun 2023 15:27:16 +0100
Pancho <Pancho.Jones@proton.me> wrote:
Yes, the first two are in my localtime, BST, but Python is giving it as
a “naive” time, it isn't using a timezone. The third one does is
recognizing timezone.
Python naive time certainly does use a timezone - it uses the best guess it can get for the local timezone which is derived as I described viz:
Or evenThis timezome shit is a red herring because it works for half past the hour
akziet = datetime.datetime.now(datetime.timezone.utc)
akzeitstr = akziet.strftime('%H:%M %Z')
On 19/06/2023 17:16, Ahem A Rivet's Shot wrote:
On Mon, 19 Jun 2023 15:27:16 +0100
Pancho <Pancho.Jones@proton.me> wrote:
Yes, the first two are in my localtime, BST, but Python is giving it as
a “naive” time, it isn't using a timezone. The third one does is
recognizing timezone.
Python naive time certainly does use a timezone - it uses the
best guess it can get for the local timezone which is derived as I described viz:
No it doesn't. As I showed, now() is not associating a timezone with
datetime objects, it could, but it doesn't.
After a bit of reading, I see that it is possible to code using the assumption that Naive python dates are UTC, and hence need no timezone.
On 18/06/2023 16:04, Dietmar Mysliwietz wrote:Hi, back again,
On Tue, 20 Jun 2023 10:03:53 +0100
Pancho <Pancho.Jones@proton.me> wrote:
On 19/06/2023 17:16, Ahem A Rivet's Shot wrote:
On Mon, 19 Jun 2023 15:27:16 +0100
Pancho <Pancho.Jones@proton.me> wrote:
Yes, the first two are in my localtime, BST, but Python is giving it as >>>> a “naive” time, it isn't using a timezone. The third one does is
recognizing timezone.
Python naive time certainly does use a timezone - it uses the
best guess it can get for the local timezone which is derived as I
described viz:
No it doesn't. As I showed, now() is not associating a timezone with
datetime objects, it could, but it doesn't.
Conversion of the unix clock (a counter of seconds since the epoch) into a human readable date and time *always* uses a timezone it is
impossible for it not to.
In the example you snipped I demonstrated that datetime.now() is sensitive to the TZ environment variable just like date. This all stems
from the low level C standard library functions which establish a default timezone based on a system default, overridden by TZ, overridden by parameters.
After a bit of reading, I see that it is possible to code using the
assumption that Naive python dates are UTC, and hence need no timezone.
In my first example that assumption would fail because the default timezone in my environment is Ireland/Dublin which is subject to DST and is currently one hour ahead of UTC but in a few months time will match UTC.
You can of course *force* python datetime (and pretty much
anything else) to use UTC by having TZ=UTC in the environment.
There's nothing magical about datetime it's just a wrapper over the
C standard library functions which is why it behaves exactly the same as
the date command in every test I have ever made.
On Tue, 20 Jun 2023 22:17:54 +0100, Pancho wrote:
I don't know what C standard library date functions are, but pythonlibrary.
datetime is more than a wrapper, maybe it is a conceptual copy of the C
implementation
I've never worked with a company that didn't have its own datetime
Interesting: My experience is the exact opposite: The first part of my working life was spent writing COBOL where you have little choice in
getting hlold of the date and.or time: ACCEPTing them from the OS returned DDMMYY until CODASYL eventually got round to adding two more digits for
the century.
Apart from that, I mostly wrote ANSI C and we never saw any reason to use anything other than the standard C library date&time functions regardless
of what countries the code would be running in.
Banking/finance apps are highly dependent on holiday calendars and day
count conventions.
I don't know what C standard library date functions are, but pythonlibrary.
datetime is more than a wrapper, maybe it is a conceptual copy of the C implementation
I've never worked with a company that didn't have its own datetime
Sysop: | Coz |
---|---|
Location: | Anoka, MN |
Users: | 2 |
Nodes: | 4 (0 / 4) |
Uptime: | 140:18:27 |
Calls: | 166 |
Files: | 5,389 |
Messages: | 223,236 |