Git Product home page Git Product logo

timespanextensions's Introduction

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

timespanextensions's People

Contributors

wizardofogz avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.