forked from joaomatossilva/DateTimeExtensions
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.
frankgeerlings/DateTimeExtensions
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
==== DateTime Extensions ==== --------------------------------------- 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. Feedback will be much appreciated. You can check out a sample (WIP) project online on http://datetimeextensions.apphb.com/ Major Features --------------------------------------- Currently implemented are the following major features: - Add or subtract Working days using locale holidays - Export Holidays to calendar format - Dates Difference in Natural Time (localized) - General "goto" dates Working Days Calculations --------------------------------------- This 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 witch 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: - 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 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 DateTimeCultureInfo("pt-PT"), 2012, textwriter); Dates Diff in Natural Time --------------------------------------- This 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: - pt-PT - pt-BR - en-US - en-GB - fr-FR - de-DE - es-ES Other Extensions: --------------------------------------- fromDate.FirstDayOfTheMonth() fromDate.LastDayOfTheMonth() fromDate.LastDayOfWeek(DayOfWeek) fromDate.NextDayOfWeek(DayOfWeek) fromDate.LastDayOfWeekOfTheMonth(DayOfWeek) fromDate.FirstDayOfWeekOfTheMonth(DayOfWeek) fromDate.GetDiff(DateTime toDate) 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. Version History --------------------------------------- v2.2.4 - bugfix: - Holidays on weekends weren't considered as holidays v2.2.3 - fixed bugs: - fixed Laborday on Canada (en-CA and fr-CA) - fixed some mobile holidays on Argentina (es-AR) - fix a bug on Autralian (en-AU) holidays strategy when moving easter holidays to next monday that was already an holiday v2.2.2 - Added new extension IsHoliday. This extension should be similar to IsWorkingDay but in reverse and disregarding the day of the week. - Internal Refactoring: Holidays strategies were refactored to allow holidays with multiple observances. v2.2.1 - Added a few more cultures: en-AU, fr-CA (en-CA), ar-SA, en-ZA, es-AR, es-MX, it-IT v2.2 - Added support for defining holidays on a different calendar - Added Jewish holidays definitions as a proof of concept v2.1.1 - Bugfix: header and date format corrected v2.1 - Added Export Holidays feature v2.0.5 - Minor internal change in adding a HolidayStrategy Superclass - DateTimeCultureInfo has now access to all holidays not regarding to the year v2.0.4 - Natural Text is now more human based on reporting months and days v2.0.3 - bugfixes: fi-FI Holidays enumeration is throwing a Argument Out Of Range Exception da-DK holiday Strategy is missnamed is-IS SeamensDay is returning Commerce Day v2.0.2 - Added nordic holidays cultures - Added new type of Holiday: NthDayOfWeekAfterDayHoliday - bugfixes: Pentecost holiday was not calculated correctly v2.0.1 - bugfixes: NthDayOfWeekInMonth Calculations were corrected v2.0 - Added Natural Time conversions features - breaking chances: - WorkingDayCulture info was renamed to DateTimeCultureInfo since it purpose has now multiple contexts. v1.2.1 - Reverted the holidays abolishment on pt-PT culture since 2012 introduced on v1.2 cause it's still being discussed on the parlament v1.2 - Changed pt-PT culture to reflect the holidays abolishment since 2012 - Added the year depedent holiday (holidays that where created since, removed since, or only verified on certain years) - breaking changes: - Holiday.GetInstance(int year) now returns DateTime? instead of DateTime - IHolidayStrategy.GetHolidaysOfYear(int year) was created to replace the property Holidays to be year independant - IHolidayStrategy.Holidays now return only the holidays of the current year v1.1 - Added more cultures - api refactoring v1.0.1 - Added more cultures - Added other general extension methods v1.0 - Initial Version. The only suported Culture is pt-PT
About
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.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- C# 100.0%