-
Notifications
You must be signed in to change notification settings - Fork 0
WizardOfOgz/TimeSpanExtensions
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
TimeSpanExt is a .NET library which makes timespans useful and easy. The functionality of TimeSpanExt greatly exceeds that of the TimeSpan class that ships with .NET. * Setup 1) Get the source: git clone git://github.com/WizardOfOgz/TimeSpanExtensions.git 2) Build the TimeSpanExtensions project 3) Include the library in your project. * Why use TimeSpanExt? - The code looks nice: DateTime searchStartDate = 1.Month().Ago; - Supports complex expressions: DateTime searchEndDate = searchStartDate + (1.Month() - 1.Day()); - Time spans can be stored and applied to more than one DateTime yielding the correct results: class ScheduleEvent { public string Name { get; set; } public DateTime StartAt { get; set; } public TimeSpanExt Duration { get; set; } public DateTime EndsAt { get{ return StartTime + Duration; } } } var vacationDuration = 1.Month(); var myVacation = new ScheduledEvent{ Name="One-month vacation", StartTime=DateTime.Parse("1/31/2011"), Duration=vacationDuration); DateTime backToWork = myVacation.EndsAt; // Feb 28, 2011 - Wait that's only 28 days from the start of my vacation! myVacation.StartTime = DateTime.Parse("3/30/2011"); // Change the start date. Duration is still one month. DateTime backToWork = myVacation.EndsAt; // Apr 30, 2011 - Much better, taking off 31 days. * Complex TimeSpanExts TimeSpanExt also supports addition and subtraction. The order of the operands is preserved as is shown in this example: var monthPlusDay = 1.Month() + 1.Day(); var dayPlusMonth = 1.Day() + 1.Month(); DateTime dt = DateTime.Parse("2/28/2010"); DateTime result; result = dt + monthPlusDay; // returns 3/29/2010 result = dt + dayPlusMonth; // returns 4/1/2010
About
This library brings truly useful TimeSpan objects to .NET
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published