forked from joaomatossilva/DateTimeExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
224 lines (168 loc) · 7.26 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
==== DateTime Extensions ====
http://kappy.github.com/DateTimeExtensions/
---------------------------------------
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.apphb.com/
Major Features
---------------------------------------
The following major features are currently implemented:
- Add or subtract Working days using locale holidays
- Export Holidays to calendar format
- Dates Difference in Natural Time (localized)
- Time of day
- General "goto" dates
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:
- 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
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:
- pt-PT
- pt-BR
- en-US
- en-GB
- fr-FR
- de-DE
- es-ES
- nl-NL
- nl-BE
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)
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.
Version History
---------------------------------------
v3.1.1
- Fixed a bug that was causing the abolished holidays to still be listed as holidays
v3.1
- Added en-NZ working days culture (Thanks @snoopydo)
- Re-removed the 4 holidays that are abolished by the PT government
v3.0.1
- Safe Locales implementation discovery
v3.0
- Culture specific strategies are now decorated with a specific attribute to allow a better and dynamic discovery.
- The Locator classes and method are now obsolete.
- DateTimeCultureInfo have been split into specific contexts. This will improve the single responsibility of the classes.
- Added Time feature
- BreakingChanges:
- DateTimeCultureInfo is split in WorkingDayCultureInfo and NaturealTextCultureInfo
- A lot of classes were moved and namespaced properly
v2.2.5
- Added nl-NL and nl-BE Natural Text Cultures (Thanks @frankgeerlings)
- bugfix:
- Multiple Holidays on the same day caused an error building the holiday map (Thanks @frankgeerlings)
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 Australian (en-AU) holidays strategy when moving Easter holidays to the 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 its 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 in Parliament
v1.2
- Changed pt-PT culture to reflect the holidays abolishment since 2012
- Added the year dependent holiday (holidays that were 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 independent
- 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 supported Culture is pt-PT