supersonicclay / csharp-date Goto Github PK
View Code? Open in Web Editor NEWImplementation of the missing C# Date struct
License: MIT License
Implementation of the missing C# Date struct
License: MIT License
I am using this Date struct in a SortedDictionary and it is throwing a SerializationException. I see that this is using the ISerializable interface but does not have the serialization constructor. I added the [Serializable] attribute in order to get it to serialize but when it tries to deserialize I get the following exception:
The constructor to deserialize an object of type 'System.Date' was not found.
Hi,
Not sure if this project is still active but I've been using it and have found a bug. If you write the following code:
Date date1 = DateTime.Now.ToDate();
System.Threading.Thread.Sleep(1000);
Date date2 = DateTime.Now().ToDate();
The date comparison functions will fail:
Assert.AreEqual(date1, date2);
Assert.IsTrue(date1==date2);
Assert.IsTrue(date1.Equals(date2));
This is because there is still a small time portion in the structure in the form of Ticks.
Fortunately there is a way round it - if you change the constructors to no longer Add hours, days etc and change them both to use ".Date":
public Date(DateTime dateTime)
{
this._dt = dateTime.Date;
}
Apparently using
dateTime.Subtract(dateTime.TimeOfDay)
also works, but I haven't tried that.
Cheers,
Dan.
I noticed that your implementation does not include a Ticks property. My guess at your reasoning would be that Ticks are far too precise for an object that represents 24-hour intervals. However, I have found that including Ticks helps with some of my code that expects this property and so I think that this property is still useful to keep around. My implementation is included below.
What are your thoughts on this? Do you have any strong arguments against including this property?
public long Ticks
{
get
{
return this._dt.Date.Ticks;
}
}
Hi,
Great work on this.
Got a couple of ideas on this:
date.ToString("o")
I think it should output yyyy-MM-dd
rather than including the time component like it does at the moment. (maybe the same when using .ToString("s")
)Thanks!
FYI.
I just discovered that System.Time
package from https://github.com/dotnet/corefxlab
System.Time. This project augments the date and time APIs in .NET. It adds two new core types: Date and TimeOfDay. It also provides extension methods to enhance the functionality of the existing DateTime, DateTimeOffset and TimeZoneInfo types.
CoreFx is experimental features that the team is trialling, there is no guarantee that they'll be included in the BCL or supported.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.