|
I'm sure you already know this, but you can also test for IsDaylightSavingTime on the returned TimeZoneInfo.
I built a web-based (Azure) timeclock app several years ago and got schooled in handling times/timespans.
"Go forth into the source" - Neal Morse
"Hope is contagious"
|
|
|
|
|
|
Never heard of it, but it must be good if it's Jon Skeet's!
Trying to keep this as simple as possible though
|
|
|
|
|
I heavily second this suggestion - the built in DateTime has a bunch of deficiencies this blog post by Jon Skeet: Noda Time: What's wrong with DateTime anyway? is, as ever excellent.
Even with NodaTime I work in Instant s (analogous to UTC) as much as possible, converting from local dates on the way in and to local dates on the way out.
|
|
|
|
|
Didn't you know about DateTime.ToLocalTime Method (System) | Microsoft Docs[^] ?
And by the way... as someone who has traveled quite a bit (crossing time zones)... please listen to the guys...
TL;DR; save data in UTC. Show data / interact with user in local.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Nelek wrote: Didn't you know about DateTime.ToLocalTime Method (System) | Microsoft Docs[^] ?
That's a giant trap if you're doing web work because it puts data in whatever is the servers timezone not the users - which can be especially fun if the hosting provider has the server running on UTC rather than the datacenter local TZ.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
|
|
|
|
|
Fair enough.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Nelek wrote: save data in UTC. Show data / interact with user in local. Actually, I just got the requirements back...
Save and show everything in just one date only, that of HQ
|
|
|
|
|
Well... if it is an "order" and it is written... they pay, they rule.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
My thoughts exactly and pretty much my company motto!
|
|
|
|
|
Offtopic...
why did you remove the c# succintly link from your signature?
I found it not that bad, that you should be ashamed of it
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
To make room for my newer Azure books
|
|
|
|
|
And I thought it was latitude and longtitude (longitude).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
And yet, and yet....
After all these years, STILL date/time handling is an unimaginable kludge, even amongst systems from one house:
Formatted date/time strings that are acceptable to SQL Server are not acceptable to MS Access JET engine (and vice versa). DATETIME objects may or may not contain the time, depending on how they are generated so you cannot reliably check that they even represent the same day without faffing about.
Despite SQL supposedly being a 'standard', just wait until you try to mix T-SQL, MySQL, PostgresSQL, Oracle etc date handling.
And then there's unix time, MS time, etc...
Back in the early days of C/C++ I used, for many, many years, my own customised version of a Borland Date library because just no-one could handle even the differences between the UK and continental Europe, let alone other countries.
I realise that a lot of these problems are not due to the coding per se - it's the weird way we humans account for and represent time and date across the globe, but you really would think that after all this time, someone, somewhere would have devised a database driven, standardised date/time handling library that could be more or less universally acceptable. We have that for most human languages - just about - after all.
|
|
|
|
|
Totally true
Date handling in JavaScript is by far the worst I've come across though.
Heck, I wouldn't even call it date handling, more like date-go- -yourself
But even in MS SQL Server, some date types recognize "2021-05-11" as a valid value, while others do not and require "20210511"
|
|
|
|
|
Here is real time programming nightmare
Arizona does not deal with daylight savings time
but that is not the issue
The Navajo Nation honors the concept of daylight savings time
AND the Hopi Nation which sits in the middle of the Navajo Nation
does not honor the concept of daylight savings time
I have often wondered how you would code for this ?
In one town if you cross the street you lose or gain an hour
|
|
|
|
|
Wow, I did not know that
Also, did you know 30 and 45 minute time zones exist?
They're (whoever they are) are not making this easy for us
|
|
|
|
|
The same thing happens in Windows Explorer with DST. A file is changed at 10 AM standard time the Friday before DST changes. If you check the time stamp on Monday it will display an hour difference. File times are UTC-ish, it is the display time zone that changes. This was Win 7 behavior; I have not verified in Win 10.
|
|
|
|
|
Rough-housing, yesterday, with my four year old grandson.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
That's great for two reasons.
1. Spending time with the grandkids is always great.
2. Knowing you can take him if it gets serious.
I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.
|
|
|
|
|
MarkTJohnson wrote: 2. Knowing you can take him if it gets serious.
We all need our illusions...
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
It is called 'Throw you down Paw Paw' at my house. My grandson is also 4 and I doubt I could take him.
Although I have been able to convert some of that energy to golf. He loves that in the back yard and at Putt Putt.
Jack of all trades, master of none, though often times better than master of one.
|
|
|
|
|
I did something similar recently, and it took me two days to recover. It's amazing how much energy a four-year old has.
|
|
|
|
|
A copper mine is perhaps overdue to cave in? (10)
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Capitulate ?
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|