NDueTime

Lightweight date & time library for .NET

Latest Release
Version 1.0.2
Source on GitHub
NDueTime
Author
Kevin Gorski

NDueTime is a collection of date & time utilities and extension methods to provide:

The scope of this project is intentionally small, but feel free to create a feature request or fork the project, add a feature, and submit a pull request.

Demos

All times are local to the server.

Parsing relative time expressions

This performs a simplified version of the Google Calendar parsing algorithm. Some things to try:

Waiting for server response
 
 
 

Creating Relative Time expressions from DateTimes

The source DateTime would normally be contextual or provided by an entity, but this should give you an idea of what to expect:

DateTime.Now.ToRelativeTimeString()
A few moments ago
5.Minutes().Ago().ToRelativeTimeString()
5 minutes ago
2.Hours().FromNow().ToRelativeTimeString()
2 hours from now

3.Days().Ago() works as well, but any TimeSpan will work.

TimeSpan.FromDays(3).Ago().ToRelativeTimeString()
3 days ago

Relative DateTime creation

The famous Rails example:

5.Minutes().Ago().ToShortTimeString()
6:29 PM

The relative part works on any TimeSpan:

TimeSpan.FromHours(2).Ago().ToShortTimeString()
4:34 PM

"From now" for future times:

15.Minutes().FromNow().ToShortTimeString()
6:49 PM

Formatting TimeSpans

Time since the beginning of the calendar year:

String.Format(new TimeSpanFormatProvider(), 
	"{0:d} days, {0:h} hours, {0:m} minutes, and {0:s} seconds", 
	DateTime.Now - new DateTime(DateTime.Today.Year, 1, 1))
49 days, 18 hours, 34 minutes, and 54 seconds

Time until the end of the calendar year:

String.Format(new TimeSpanFormatProvider(), 
	"{0:dd:hh:mm:ss}", 
	new DateTime(DateTime.Today.Year + 1, 1, 1) - DateTime.Now)
315:05:25:05