Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. I have anxiety now...

I have anxiety now...

Scheduled Pinned Locked Moved The Lounge
javascriptcloudcsharplinqcom
35 Posts 11 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Jeremy Falcon

    lmoelleb wrote:

    I use DateTimeOffset instead of storing in UTC.

    I don't do .NET these days, but would that not use the same conversions internally to figure out the offset? So, what's the advantage over just converting to UTC and sticking with it?

    Jeremy Falcon

    L Offline
    L Offline
    lmoelleb
    wrote on last edited by
    #24

    The main advantage is that it natively protect against mistakes. It does not use the same logic internally as DateTime - it stores the offset instead of DateTimeKind. You never have to deal with DateTimeKind.Unknown (primary reason for mistakes I have seen). You never have some database layer having to be told if it is local time or utc. If some idiot use local time... Then nothing happens because it still accurately represents a unique point in time - no matter where in the world that local time was used.

    J 1 Reply Last reply
    0
    • J Jeremy Falcon

      lmoelleb wrote:

      Yet I have seen a developer I would clarify as highly competent do "DateTime.Now.ToUniversalTime()".

      That in and of itself isn't bad. It would be context dependent as to whether that's bad or not.

      lmoelleb wrote:

      Yes, it is quite simple, yet mistakes happens.

      For sure, but it's not as bad as some would suggest. I'd argue dealing with OS API compatibility or browser compatibly issues are far more involved (well not as much as it used to be).

      Jeremy Falcon

      L Offline
      L Offline
      lmoelleb
      wrote on last edited by
      #25

      A local time in c# does not represent a unique point in time as it can't store A and B times when transitioning from daylight saving time to standard time. So once you go from local to universal... Good luck. But sure, maybe they chose an implementation that happens to always work in that specific case... But just realizing this is not clear is enough for me to stay clear of that problem.

      J 1 Reply Last reply
      0
      • Sander RosselS Sander Rossel

        The Problem with Time & Timezones - Computerphile - YouTube[^] And yeah, been there done that (luckily not all the exceptions discussed in this video...) :sigh:

        Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript

        J Offline
        J Offline
        Jacquers
        wrote on last edited by
        #26

        [Noda Time | Date and time API for .NET](https://nodatime.org/)

        1 Reply Last reply
        0
        • Sander RosselS Sander Rossel

          The Problem with Time & Timezones - Computerphile - YouTube[^] And yeah, been there done that (luckily not all the exceptions discussed in this video...) :sigh:

          Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript

          B Offline
          B Offline
          BernardIE5317
          wrote on last edited by
          #27

          Be thankful Special and General Relativistic effects are not considered. "I once put instant coffee into the microwave and went back in time." - Steven Wright

          1 Reply Last reply
          0
          • J Jeremy Falcon

            Totally agree. Well, except I believe that everything should be stored in UTC. Just get used to it already. But, especially before the Internet and globalization, anti-timezone peeps act like not having a timezone would be better. But, just imagine the chaos of morning sunrise happening at 11:00PM. It's just trading one confusion for another. People want to act smart by looking behind them (easy to do) and insulting things. But, I can promise, given the state of the world, most everyone would be agreeing to use them if they were alive and well during that time. IMO daylight savings time did more harm than timezones. Again, I can see why it was created. But, it caused more issues than timezones. Timezones were never really an issue.

            Jeremy Falcon

            Sander RosselS Offline
            Sander RosselS Offline
            Sander Rossel
            wrote on last edited by
            #28

            Jeremy Falcon wrote:

            Well, except I believe that everything should be stored in UTC.

            I did this and then calculated back to the current time zone. So then the customer called and said someone did something in the middle of the night, which was unthinkable. After looking it up I said that person was in another time zone (on vacation) and did something that was middle of the night for him. It was decided that everything should always be stored and shown in their HQ time zone, even when on vacation or when the apocalypse hits. Loved the simplicity, stored current time and never looked back :D

            Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript

            J 1 Reply Last reply
            0
            • L lmoelleb

              Why would it be a bad idea to store DateTimeOffset? The way to store date/time I have the most experience with is DateTime stored as UTC. But I see no reason to go back to that - what is the benefit?

              J Offline
              J Offline
              Jeremy Falcon
              wrote on last edited by
              #29

              My understanding of DateTimeOffset is that it's still a local time, but with offset information. Soooooo, if I'm correct with that... The reason why it's bad is you're adding complexity for no real gain. That date time is still only relevant to you. If you have an application that is used all over the world, then you now must do two calculations to show a time to a user rather than one.

              Jeremy Falcon

              1 Reply Last reply
              0
              • L lmoelleb

                The main advantage is that it natively protect against mistakes. It does not use the same logic internally as DateTime - it stores the offset instead of DateTimeKind. You never have to deal with DateTimeKind.Unknown (primary reason for mistakes I have seen). You never have some database layer having to be told if it is local time or utc. If some idiot use local time... Then nothing happens because it still accurately represents a unique point in time - no matter where in the world that local time was used.

                J Offline
                J Offline
                Jeremy Falcon
                wrote on last edited by
                #30

                Well, I don't know enough about the C# structures to speak intelligently on the matter. So, there's an 82.5% chance I'm talking out of my arse. :laugh: But, generally speaking, it's bad to store anything in local time. And trying to make code idiot proof is impossible, especially at the expense of making the code harder to follow. That's what code reviews are for. You're adding more complication to the product just because of a DateTimeKind.Unknown situation when it's so much easier to just keep everything in UTC.

                Jeremy Falcon

                1 Reply Last reply
                0
                • L lmoelleb

                  A local time in c# does not represent a unique point in time as it can't store A and B times when transitioning from daylight saving time to standard time. So once you go from local to universal... Good luck. But sure, maybe they chose an implementation that happens to always work in that specific case... But just realizing this is not clear is enough for me to stay clear of that problem.

                  J Offline
                  J Offline
                  Jeremy Falcon
                  wrote on last edited by
                  #31

                  Wouldn't that make UTC more appealing then? Then you only have to do one conversion when going back to local.

                  Jeremy Falcon

                  L 1 Reply Last reply
                  0
                  • Sander RosselS Sander Rossel

                    Jeremy Falcon wrote:

                    Well, except I believe that everything should be stored in UTC.

                    I did this and then calculated back to the current time zone. So then the customer called and said someone did something in the middle of the night, which was unthinkable. After looking it up I said that person was in another time zone (on vacation) and did something that was middle of the night for him. It was decided that everything should always be stored and shown in their HQ time zone, even when on vacation or when the apocalypse hits. Loved the simplicity, stored current time and never looked back :D

                    Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript

                    J Offline
                    J Offline
                    Jeremy Falcon
                    wrote on last edited by
                    #32

                    So then display the time info in the appropriate time. There's no rule saying you can't do that. UTC is just internal to the app. Good luck doing datetime math in local time all over the world. It'll be a living nightmare.

                    Jeremy Falcon

                    1 Reply Last reply
                    0
                    • J Jeremy Falcon

                      Totally agree. Well, except I believe that everything should be stored in UTC. Just get used to it already. But, especially before the Internet and globalization, anti-timezone peeps act like not having a timezone would be better. But, just imagine the chaos of morning sunrise happening at 11:00PM. It's just trading one confusion for another. People want to act smart by looking behind them (easy to do) and insulting things. But, I can promise, given the state of the world, most everyone would be agreeing to use them if they were alive and well during that time. IMO daylight savings time did more harm than timezones. Again, I can see why it was created. But, it caused more issues than timezones. Timezones were never really an issue.

                      Jeremy Falcon

                      N Offline
                      N Offline
                      Nelek
                      wrote on last edited by
                      #33

                      Jeremy Falcon wrote:

                      IMO daylight savings time did more harm than timezones.

                      1000% this

                      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.

                      1 Reply Last reply
                      0
                      • J Jeremy Falcon

                        Wouldn't that make UTC more appealing then? Then you only have to do one conversion when going back to local.

                        Jeremy Falcon

                        L Offline
                        L Offline
                        lmoelleb
                        wrote on last edited by
                        #34

                        It seems you are under the impression I am preferring local time instead of UTC time. I do not. I prefer DateTimeOffset over DateTime. With DateTime you have to be carefull not making mistakes. DateTimeOffset eliminates several of these possible mistakes.

                        J 1 Reply Last reply
                        0
                        • L lmoelleb

                          It seems you are under the impression I am preferring local time instead of UTC time. I do not. I prefer DateTimeOffset over DateTime. With DateTime you have to be carefull not making mistakes. DateTimeOffset eliminates several of these possible mistakes.

                          J Offline
                          J Offline
                          Jeremy Falcon
                          wrote on last edited by
                          #35

                          lmoelleb wrote:

                          It seems you are under the impression I am preferring local time instead of UTC time. I do not.

                          Gotcha

                          Jeremy Falcon

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups