|
1 | | -# FlexibleParser |
| 1 | +# DateParser |
2 | 2 |
|
3 | | -[](https://doi.org/10.5281/zenodo.439945) [](https://travis-ci.org/varocarbas/FlexibleParser) |
| 3 | +[Master source code](https://github.com/varocarbas/FlexibleParser/tree/master/all_code/DateParser/Source) |
4 | 4 |
|
| 5 | +[https://customsolvers.com/date_parser/](https://customsolvers.com/date_parser/) (ES: [https://customsolvers.com/date_parser_es/](https://customsolvers.com/date_parser_es/)) -- [NuGet package](https://www.nuget.org/packages/DateParser/) -- [Video](https://www.youtube.com/watch?v=E2JT2w66uyc) |
5 | 6 |
|
6 | | -FlexibleParser is a multi-purpose .NET parsing library based upon the following ideas: |
| 7 | +## Introduction |
7 | 8 |
|
8 | | -- Intuitive, adaptable and easy to use. |
9 | | -- Pragmatic, but aiming for the maximum accuracy and correctness. |
10 | | -- Overall compatible and easily automatable. |
11 | | -- Formed by independent DLLs managing specific situations. |
| 9 | +After adding a reference to the ```FlexibleParser``` namespace, it is possible to start using DateParser right away. The main functionalities of this library can be divided in the following two groups: |
| 10 | +- ```DateTime``` type (C#) enhancements: better string parsing, easier linkage to time zone information and easier modification of constituent elements. |
| 11 | +- Time zones: relevant amount of additional information and more user-friendly usage. |
12 | 12 |
|
13 | | -## Parts |
| 13 | +All the public classes of DateParser have some common features meant to maximise their usability and compatibility. For example, implicit conversions to multiple types or custom ```ToString()``` versions outputting the most adequate information. |
14 | 14 |
|
15 | | -At the moment, FlexibleParser is formed by the following independent parts: |
| 15 | +```C# |
| 16 | +//dateP.Value is identical to DateTime.Parse("01-01-2001"). |
| 17 | +DateP dateP = new DateP("01-01-2001"); |
| 18 | +dateP = "01-01-2001"; |
16 | 19 |
|
17 | | -[](https://doi.org/10.5281/zenodo.439729) [UnitParser](https://customsolvers.com/unit_parser/) ([last release](https://github.com/varocarbas/FlexibleParser/releases/tag/UnitParser__1.0.6301.23655), [readme file](https://github.com/varocarbas/FlexibleParser/blob/master/all_readme/UnitParser.md), [code analysis](https://varocarbas.com/unit_parser_code/))<br/> |
18 | | -It allows to easily deal with a wide variety of situations involving units of measurement. |
19 | | -Among its most salient features are: user-defined exception triggering and gracefully managing numeric values of any size. |
| 20 | +//dateP.Value has the same date than DateTime.ParseExact("02-01-2001", "dd-MM-yyyy", CultureInfo.CurrentCulture) |
| 21 | +//and the current time. |
| 22 | +dateP = new DateP("02-01-2001", new CustomDateTimeFormat("day-month-year")); |
20 | 23 |
|
| 24 | +//timeZoneWindows.TimeZoneInfo is identical to TimeZoneInfo.FindSystemTimeZoneById("E. Europe Standard Time"). |
| 25 | +//Note that TimeZoneInfo.FindSystemTimeZoneById("E Europe Standard Time") triggers an exception. |
| 26 | +TimeZoneWindows timeZoneWindows = new TimeZoneWindows(TimeZoneWindowsEnum.E_Europe_Standard_Time); |
| 27 | +timeZoneWindows = TimeZoneWindowsEnum.E_Europe_Standard_Time; |
| 28 | +``` |
21 | 29 |
|
22 | | -[](https://doi.org/10.5281/zenodo.439942) [NumberParser](https://customsolvers.com/number_parser/) ([last release](https://github.com/varocarbas/FlexibleParser/releases/tag/NumberParser_1.0.6302.28051), [readme file](https://github.com/varocarbas/FlexibleParser/blob/master/all_readme/NumberParser.md), [code analysis](https://varocarbas.com/number_parser_code/))<br/>It provides a common framework for all the .NET numeric types. Main features: exceptions managed internally; beyond-double-range support; custom mathematical functionalities. |
| 30 | +## DateP |
23 | 31 |
|
| 32 | +```DateP``` is the main class of DateParser and improves ```DateTime``` in the following ways: |
| 33 | +- It enables new alternatives to extract the date/time information from strings via ```CustomDateTimeFormat```. |
| 34 | +- It allows real-time modifications of the ```DateTime``` constituent parts, including the offset of the associated time zone. |
24 | 35 |
|
25 | | -[DateParser](https://customsolvers.com/date_parser/) ([last release](https://github.com/varocarbas/FlexibleParser/tree/master/all_code/DateParser/Source), [readme file](https://github.com/varocarbas/FlexibleParser/blob/master/all_readme/DateParser.md))<br/>It enhances the default .NET date/time support, mostly via improving the usability of its main type and accounting for a big amount of additional time zone information. |
26 | 36 |
|
| 37 | +```C# |
| 38 | +string[] inputs = new string[] |
| 39 | +{ |
| 40 | + "04-05-2017", "4-may-2017", "04/5-2017", "04 05 2017" |
| 41 | +}; |
27 | 42 |
|
28 | | -## Authorship & Copyright |
| 43 | +foreach (string input in inputs) |
| 44 | +{ |
| 45 | + DateP dateP = new DateP |
| 46 | + ( |
| 47 | + input, new CustomDateTimeFormat |
| 48 | + ( |
| 49 | + new DateTimeParts[] |
| 50 | + { |
| 51 | + DateTimeParts.Day, DateTimeParts.Month, DateTimeParts.Year |
| 52 | + } |
| 53 | + ), |
| 54 | + 0m |
| 55 | + ); |
| 56 | + |
| 57 | + //dateP.Value has always the same date than DateTime.ParseExact("04-05-2017", "dd-MM-yyyy", CultureInfo.CurrentCulture) |
| 58 | + //and the current time. |
| 59 | + //Note that DateTime.ParseExact requires specific arguments to deal with each input string. |
| 60 | +} |
| 61 | + |
| 62 | +//The date of dateP.Value has become 05/05/2017, the first Friday after 04/05/2017. |
| 63 | +dateP.Week = DayOfWeek.Friday; |
| 64 | + |
| 65 | +//The time of dateP.Value is now 3 hours later, the lag between the new offset and the original one. |
| 66 | +dateP.TimeZoneOffset = 3m; |
| 67 | +``` |
| 68 | + |
| 69 | +## Time Zones |
| 70 | + |
| 71 | +DateParser supports 6 different types of time zones, each of them is defined by a main class and an enum: |
| 72 | +- [```TimeZoneOfficial```](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/DateParser/Source/TimeZones/Types/Official/TimeZones_Types_Official_Constructors.cs)/[```TimeZoneOfficialEnum```](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/DateParser/Source/TimeZones/Types/Official/Hardcoding/TimeZones_Types_Official_Hardcoding_Main.cs). |
| 73 | +- [```TimeZoneIANA```](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/DateParser/Source/TimeZones/Types/IANA/TimeZones_Types_IANA_Constructors.cs)/[```TimeZoneIANAEnum```](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/DateParser/Source/TimeZones/Types/IANA/Hardcoding/TimeZones_Types_IANA_Hardcoding_Main.cs). |
| 74 | +- [```TimeZoneConventional```](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/DateParser/Source/TimeZones/Types/Conventional/TimeZones_Types_Conventional_Constructors.cs)/[```TimeZoneConventionalEnum```](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/DateParser/Source/TimeZones/Types/Conventional/TimeZones_Types_Conventional_Hardcoding.cs). |
| 75 | +- [```TimeZoneUTC```](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/DateParser/Source/TimeZones/Types/UTC/TimeZones_Types_UTC_Constructors.cs)/[```TimeZoneUTCEnum```](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/DateParser/Source/TimeZones/Types/UTC/TimeZones_Types_UTC_Hardcoding.cs). |
| 76 | +- [```TimeZoneWindows```](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/DateParser/Source/TimeZones/Types/Windows/TimeZones_Types_Windows_Constructors.cs)/[```TimeZoneWindowsEnum```](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/DateParser/Source/TimeZones/Types/Windows/TimeZones_Types_Windows_Hardcoding.cs). |
| 77 | +- [```TimeZoneMilitary```](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/DateParser/Source/TimeZones/Types/Military/TimeZones_Types_Military_Constructors.cs)/[```TimeZoneMilitaryEnum```](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/DateParser/Source/TimeZones/Types/Military/TimeZones_Types_Military_Hardcoding.cs). |
| 78 | + |
| 79 | +There are also two other classes dealing with various time zones at the same time: |
| 80 | +- [```TimeZones```](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/DateParser/Source/TimeZones/Basic/Constructors/MainClass/TimeZones_Basic_Constructors_MainClass_Main.cs). |
| 81 | +- [```TimeZonesCountry```](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/DateParser/Source/TimeZones/Country/TimeZones_Country_Constructors.cs). |
29 | 82 |
|
| 83 | + |
| 84 | +```C# |
| 85 | +//All the information about the CET time zone. |
| 86 | +TimeZoneOfficial timeZoneOfficial = "CET"; |
| 87 | + |
| 88 | +//Time zones of all the types having something in common with the CET time zone. |
| 89 | +TimeZones timezones = new TimeZones(timeZoneOfficial); |
| 90 | + |
| 91 | +//List with all the pairs of official standard/daylight time zones used in Ponferrada's country (i.e., Spain). |
| 92 | +TimeZonesCountry timeZonesCountry = new TimeZonesCountry("Ponferrada"); |
| 93 | +``` |
| 94 | + |
| 95 | +## Further Code Samples |
| 96 | +The [test application](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/Test/Parts/DateParser.cs) includes a relevant number of descriptive code samples. |
| 97 | + |
| 98 | +## Authorship & Copyright |
30 | 99 | I, Alvaro Carballo Garcia (varocarbas), am the sole author of each single bit of this code. |
31 | 100 |
|
32 | 101 | Equivalently to what happens with all my other online contributions, this code can be considered public domain. For more information about my copyright/authorship attribution ideas, visit the corresponding pages of my sites: |
33 | 102 | - https://customsolvers.com/copyright/<br/> |
34 | 103 | ES: https://customsolvers.com/copyright_es/ |
35 | 104 | - https://varocarbas.com/copyright/<br/> |
36 | | -ES: https://varocarbas.com/copyright_es/ |
| 105 | +ES: https://varocarbas.com/copyright_es/ |
0 commit comments