Giter Site home page Giter Site logo

sambeauvois / datetimeextensions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from joaomatossilva/datetimeextensions

0.0 1.0 0.0 22.85 MB

This project is a merge of several common DateTime operations on the form of extensions to System.DateTime, including natural date difference text (precise and human rounded), holidays and working days calculations on several culture locales.

Home Page: http://datetimeextensions.azurewebsites.net/

License: Other

PowerShell 0.56% Shell 0.48% C# 98.96%

datetimeextensions's Introduction

DateTimeExtensions

DateTime Extensions

http://www.kspace.pt/DateTimeExtensions/

NuGet Version MyGet Pre Release AppVeyor GitHub contributors

This project is a merge of several common DateTime operations in the form of extensions to System.DateTime, including natural date difference text (precise and human rounded), holidays and working days calculations on several culture locales.

Feedback will be much appreciated. You can check out a sample (WIP) project online on http://datetimeextensions.azurewebsites.net/

Major Features

The following major features are currently implemented:

  • Add or subtract Working days using locale holidays
  • Support for Regional holidays (limited locales)
  • Export Holidays to calendar format
  • Dates Difference in Natural Time (localized)
  • Time of day
  • General "goto" dates
  • Supports SourceLink for debugging

Working Days Calculations

These extensions for System.DateTime adds methods to make calculations based on working days. A working day is defined in IWorkingDayCultureInfo in two ways:

IsWorkingDay(DayOfWeek dayOfWeek)
IsWorkingDay(DateTime date)

The first defines which day of the week is a working day (by default, working days are all week days except weekends). The last does the same as the first, but it's also able to check for any holiday. By default, no holidays are defined, unless there is a IWorkingDayCultureInfo implemented for the current thread CultureInfo.

Avaiable CultureInfo implementations:

Culture Culture
pt-PT da-DK
pt-BR fi-FI
en-US is-IS
en-GB nb-NO
fr-FR nl-NL
de-DE sv-SE
es-ES es-AR
es-MX en-AU
en-ZA fr-CA (en-CA)
ar-SA it-IT
en-NZ en-GD (gd-GD, not really sure about this locale)
en-IE sl-SL
kr-KR zh-CN
pl-PL vi-VN

If your culture is not listed here you can contribute it!!!

Fork me, implement it and send me the pull request, or just create an issue on the project github site.

Export Holidays to calendar format

This feature allows you to export the holidays from a DateTimeCultureInfo (see above) and export it to Microsoft Office Outlook. The IExportHolidaysFormat interface exposes one simple method for it:

void Export(DateTimeCultureInfo dateTimeCultureInfo, int year, TextWriter writer)

Example:

var exporter = ExportHolidayFormatLocator.LocateByType(ExportType.OfficeHolidays);
exporter.Export(new WorkingDayCultureInfo("pt-PT"), 2012, textwriter);

Dates Diff in Natural Time

These extensions can compare two dates in natural language based on the current locale on current thread CultureInfo. There are 2 API points for them:

fromDate.ToNaturalText(toTime, bool round = true)
fromDate.ToExactNaturalText(toTime)

The first will return the most valuable time component with value > 0. The round flag will try to round the most significant time component based on the next least significant. Also, the round flag will round minutes and seconds to quarters after the first one.

Avaiable CultureInfo implementations:

Culture
pt-PT
pt-BR
en-US
en-GB
fr-FR
de-DE
es-ES
nl-NL
nl-BE
kr-KR
pl-PL

Time of Day

These extensions allow easy parsing of time expressions and add the ability to check if a DateTime instance is after, before or inside a period.

bool IsBetween(this DateTime dateTime, Time startTime, Time endTime)
bool IsBefore(this DateTime dateTime, Time time)
bool IsAfter(this DateTime dateTime, Time time)

Other Extensions:

fromDate.FirstDayOfTheMonth()
fromDate.LastDayOfTheMonth()
fromDate.LastDayOfWeek(DayOfWeek)
fromDate.NextDayOfWeek(DayOfWeek)
fromDate.LastDayOfWeekOfTheMonth(DayOfWeek)
fromDate.FirstDayOfWeekOfTheMonth(DayOfWeek)
fromDate.GetDiff(DateTime toDate)

SourceLink

This library supports SourceLink. Just make sure you have a compatible Visual Studio version and the Just My Code is disabled on Debugging options

How to Contribute

Feel free to fork the project, work on your fork and send me the pull requests. You can also create issues with the features or changes that you think important.

Also, this repository is built with autocrlf = true.

Holidays Names

When adding holidays resources names, plase prefix the culture specific holidays with the country name to avoid name colisison. Example: Portugal_FreedomDay

Changelog

Changelog

License

License

Special Thanks

  • @manuelbarbosa for making me this awesome logo
  • @matkoch for helping me build the build script using Nuke and also building a video using this project
  • Jetbrains for allowing me an open source license of their pretty cool suit Jetbrains

datetimeextensions's People

Contributors

canro91 avatar cuongtranba avatar dalmuti509 avatar frankgeerlings avatar isepise avatar jbasinger avatar joaomatossilva avatar jzeferino avatar martin308 avatar schulz3000 avatar sihugh-duplicate avatar snoopydo avatar tfreitasleal avatar william001 avatar

Watchers

 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.