wsick / Fayde

Inspired by Silverlight; XAML engine using Javascript and rendering to the HTML5 Canvas.
MIT License
189 stars 27 forks source link

DateTime.Today gives wrong date #134

Closed Sally-Xu closed 9 years ago

Sally-Xu commented 9 years ago

My current local time is 6/20/2015 10PM, Here is Fayde's DateTime.Today's output in the debug watch window:

Date: DateTime Day: 21 DayOfWeek: 0 DayOfYear: 170 Hour: 0 Kind: 2 Millisecond: 0 Minute: 0 Month: 6 Second: 0 Ticks: 1434844800000 TimeOfDay: (...) Year: (...) _InternalDate: Sat Jun 20 2015 20:00:00 GMT-0400 (US Eastern Daylight Time)

Notice the Day is 21 instead of 20.

Shouldn't the default Kind be Local instead of UTC?

BSick7 commented 9 years ago

Fixed in 0.16.39.

Sally-Xu commented 9 years ago

The fix only fixed DateTime.Today. But there is new problem.

If I create a date with the following code:

var d = new DateTime(2015, 6, 29) // this is today's date, so it should be the same as d.Date

I tried to compare the dates using Datetime.Compare and got the following result:

DateTime.Compare(d.Date, d) ! = 0 // this is not expected

or

DateTime.Compare(d.Date, DateTime.Today) ! = 0

d.Ticks has different value than d.Date.Ticks.

var d1 = DateTime.Today; // Default Kind is 1 var d = new DateTime(2015, 6, 29) // Default Kind is 2

I think the default "Kind" should be set to 1 ("Local") for all constructors of DateTime except for the one which takes "Kind" as a input parameter.

BSick7 commented 9 years ago

From the latest build, this is what I get in Chrome.

screen

Sally-Xu commented 9 years ago

Did you try DateTime.Compare(new DateTime(2015, 6, 29).Date, DateTime.Today)

BSick7 commented 9 years ago

Updated comment.

Sally-Xu commented 9 years ago

Strange, now I try it, got the same result as yours. But I definitely saw different result when I first updated Fayde library this evening. never mind then.