karishmal / google-api-dotnet-client

Automatically exported from code.google.com/p/google-api-dotnet-client
Apache License 2.0
0 stars 0 forks source link

Datetime parsing #436

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
From a mail I got from one of our NuGet packages users:

To make a long story short: he wants to be able to get the json string itself 
or supporting DateTimeOffset.

I think that we should support the first option.

That's his original mail:

Maybe I could (use DateTime in UTC), but the timezone is an issue. The DateTime 
structure doesn't have any idea about what timezone it is. So it either says 
it's a local time or it's a gmt time. When I go to UTC, then it takes the 
current thread culture timezone settings... It's a lot of fuzz to make it work 
with datetime objects. As I mentioned in my first mail I think, DateTimeOffset 
is the better alternative. However, I'd still like to be able to parse it in my 
own code so I can be sure that I follow best practices wrt globalization in 
string handling instead of relying on a serializer.
Might be voodoo, but it makes me feel better. :)
Finally, when debugging timezones, it's very valuable to be able to trace the 
original string value without Fiddler. 

Maybe something like this could work if you want to use a DateTime?
(it's just a sketch, I haven't tested it)

        [Newtonsoft.Json.JsonIgnore]
        public virtual System.Nullable<System.DateTime> DateTime 
        {
            get 
            { 
                System.DateTime? result = null;
                System.DateTime parsed;
                if (System.DateTime.TryParse(this.DateTimeRaw, out parsed))
                {
                    result = parsed;
                }

                return result;
            }
            set 
            {
                if (null != value)
                {
                    this.DateTimeRaw = value.Value.ToUniversalTime().ToString("s") + "Z";
                }
                else
                {
                    this.DateTimeRaw = string.Empty;
                }
            }
        }
        [Newtonsoft.Json.JsonPropertyAttribute("dateTime")]
        public virtual string DateTimeRaw { get; set; } 

Original issue reported on code.google.com by pele...@google.com on 23 Dec 2013 at 7:23

GoogleCodeExporter commented 9 years ago
https://codereview.appspot.com/46920043/

TODO: change the templates as well

Original comment by pele...@google.com on 10 Jan 2014 at 5:00

GoogleCodeExporter commented 9 years ago
The code was committed in this repository. 
TODO: change the templates on Google backend

Original comment by pele...@google.com on 13 Jan 2014 at 7:52

GoogleCodeExporter commented 9 years ago

Original comment by pele...@google.com on 27 Jan 2014 at 9:30