├── tests └── Aqua.DateTimeHelpers.Tests │ ├── Aqua.DateTimeHelpers.Tests.csproj │ └── DateTimeHelpersTests.cs ├── .github └── workflows │ └── dotnet-core.yml ├── src ├── Aqua.DateTimeHelpers │ ├── Aqua.DateTimeHelpers.csproj │ ├── LICENSE │ └── DateTimeHelpers.cs └── LICENSE ├── LICENSE ├── LICENSE.md ├── Aqua.DateTimeHelpers.sln ├── .gitignore └── README.md /tests/Aqua.DateTimeHelpers.Tests/Aqua.DateTimeHelpers.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | false 7 | 8 | 9 | 10 | 11 | all 12 | runtime; build; native; contentfiles; analyzers; buildtransitive 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /.github/workflows/dotnet-core.yml: -------------------------------------------------------------------------------- 1 | name: .NET Core 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | env: 10 | NUGET_SOURCE_URL: 'https://api.nuget.org/v3/index.json' 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Setup .NET Core 20 | uses: actions/setup-dotnet@v1 21 | with: 22 | dotnet-version: 3.1.301 23 | - name: Install dependencies 24 | run: dotnet restore 25 | - name: Build 26 | run: dotnet build --configuration Release --no-restore 27 | - name: Test 28 | run: dotnet test --no-restore --verbosity normal 29 | - name: 'Pack Project' 30 | run: dotnet pack --configuration Release 31 | - name: 'Push package' 32 | run: dotnet nuget push 'src/Aqua.StringHelpers/bin/Release/*.nupkg' -k ${{ secrets.NUGET_AUTH_TOKEN }} -s ${{ env.NUGET_SOURCE_URL }} 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/Aqua.DateTimeHelpers/Aqua.DateTimeHelpers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | Is an Open Source and Free Software package to facilitate dealing with Date and Time, It supports all .NET Core versions as well as .NET Framework 4.6.1+ 6 | Useme Alehosaini 7 | 8 | https://ualehosaini.github.io/aqua-date-time-helpers.html 9 | https://github.com/ualehosaini/Aqua.DateTimeHelpers 10 | git 11 | date time datetime helpers .net 12 | true 13 | snupkg 14 | LICENSE.md 15 | 1.0.1 16 | 17 | 18 | 19 | 20 | True 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Useme Alehosaini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Useme Alehosaini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Useme Alehosaini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/Aqua.DateTimeHelpers/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Useme Alehosaini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Aqua.DateTimeHelpers.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30611.23 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{032091C9-D941-40FB-A7EA-989DC013BD40}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{53CF0B62-009E-4092-83D0-410030EFD940}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "others", "others", "{85A275EC-77C0-4804-B6AB-ABD6052B51FF}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aqua.DateTimeHelpers", "src\Aqua.DateTimeHelpers\Aqua.DateTimeHelpers.csproj", "{C0CA9359-DA8C-4C7D-B8CA-EB9D9306C20D}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aqua.DateTimeHelpers.Tests", "tests\Aqua.DateTimeHelpers.Tests\Aqua.DateTimeHelpers.Tests.csproj", "{44D4063B-3199-418D-BA58-63F0529196DF}" 15 | EndProject 16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{DE459EC5-D016-43C7-8743-A4E05C0370DF}" 17 | EndProject 18 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflow", "workflow", "{27D14E59-51B1-41D0-8913-EA8C9ECF0CD3}" 19 | EndProject 20 | Global 21 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 22 | Debug|Any CPU = Debug|Any CPU 23 | Release|Any CPU = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {C0CA9359-DA8C-4C7D-B8CA-EB9D9306C20D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {C0CA9359-DA8C-4C7D-B8CA-EB9D9306C20D}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {C0CA9359-DA8C-4C7D-B8CA-EB9D9306C20D}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {C0CA9359-DA8C-4C7D-B8CA-EB9D9306C20D}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {44D4063B-3199-418D-BA58-63F0529196DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {44D4063B-3199-418D-BA58-63F0529196DF}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {44D4063B-3199-418D-BA58-63F0529196DF}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {44D4063B-3199-418D-BA58-63F0529196DF}.Release|Any CPU.Build.0 = Release|Any CPU 34 | EndGlobalSection 35 | GlobalSection(SolutionProperties) = preSolution 36 | HideSolutionNode = FALSE 37 | EndGlobalSection 38 | GlobalSection(NestedProjects) = preSolution 39 | {C0CA9359-DA8C-4C7D-B8CA-EB9D9306C20D} = {032091C9-D941-40FB-A7EA-989DC013BD40} 40 | {44D4063B-3199-418D-BA58-63F0529196DF} = {53CF0B62-009E-4092-83D0-410030EFD940} 41 | {27D14E59-51B1-41D0-8913-EA8C9ECF0CD3} = {DE459EC5-D016-43C7-8743-A4E05C0370DF} 42 | EndGlobalSection 43 | GlobalSection(ExtensibilityGlobals) = postSolution 44 | SolutionGuid = {2753340F-9747-4E29-900C-EEBC06263C44} 45 | EndGlobalSection 46 | EndGlobal 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | /APOC.Backend.Api/Logs 332 | -------------------------------------------------------------------------------- /src/Aqua.DateTimeHelpers/DateTimeHelpers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Threading; 6 | 7 | namespace Aqua.DateTimeHelpers 8 | { 9 | public static class DateTimeHelpers 10 | { 11 | private static readonly DateTime _epochDateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); 12 | private static readonly long _epochTicks = 621355968000000000L; 13 | 14 | /// 15 | /// Check the combination of Year, Month, and Day is a Valid Date 16 | /// 17 | /// 18 | /// 19 | /// 20 | /// 21 | public static bool IsValidDate(int year, int month, int day) => year >= DateTime.MinValue.Year && 22 | year <= DateTime.MaxValue.Year && 23 | month >= 1 && 24 | month <= 12 && 25 | day >= 1 && 26 | DateTime.DaysInMonth(year, month) >= day; 27 | 28 | /// 29 | /// Check the combination of Hour, Minute, and Second is a Valid Time 30 | /// 31 | /// 32 | /// 33 | /// 34 | /// 35 | public static bool IsValidTime(int hour, int minute, int second = 0) => hour >= 0 && 36 | hour <= 23 && 37 | minute >= 0 && 38 | minute <= 59 && 39 | second >= 0 && 40 | second <= 59; 41 | 42 | /// 43 | /// Check the combination of Year, Month, Day, Hour, Minute, and Second is a Valid DateTime 44 | /// 45 | /// 46 | /// 47 | /// 48 | /// 49 | /// 50 | /// 51 | /// 52 | public static bool IsValidDateTime(int year, int month, int day, int hour, int minute, int second = 0) => IsValidDate(year, month, day) && 53 | IsValidTime(hour, minute, second); 54 | 55 | /// 56 | /// To Convert Unix 57 | /// Time Stamp To DateTime 58 | /// 59 | /// 60 | /// 61 | public static DateTime UnixTimeStampToDateTime(double unixTimeStamp) => new DateTime(_epochDateTime.AddSeconds(unixTimeStamp).ToLocalTime().Ticks); 62 | 63 | /// 64 | /// To Convert Unix Time Stamp To DateTimeUTC 65 | /// 66 | /// 67 | /// 68 | public static DateTime UnixTimeStampToDateTimeUTC(double unixTimeStamp) => _epochDateTime.AddSeconds(unixTimeStamp); 69 | 70 | /// 71 | /// To Convert DateTime To Unix Time Stamp 72 | /// 73 | /// 74 | /// 75 | public static double DateTimeToUnixTimeStamp(DateTime dateTime) => (dateTime.ToUniversalTime().Ticks - _epochTicks) / TimeSpan.TicksPerSecond; 76 | 77 | /// 78 | /// Check the input if it is within a range of DateTime 79 | /// 80 | /// 81 | /// 82 | /// 83 | /// 84 | public static bool IsBetween(this DateTime input, DateTime rangeBegining, DateTime rangeEnd) => input.Ticks >= rangeBegining.Ticks && 85 | input.Ticks < rangeEnd.Ticks; 86 | 87 | /// 88 | /// Returns the DateTime.MinValue 89 | /// 90 | /// 91 | public static DateTime GetMinDate() => DateTime.MinValue; 92 | 93 | /// 94 | /// Ignore Specific DateTime Part 95 | /// 96 | /// 97 | /// 98 | /// 99 | public static DateTime IgnoreTimeSpan(this DateTime dateTime, TimeSpan timeSpan) 100 | { 101 | if (timeSpan == TimeSpan.Zero) 102 | return dateTime; 103 | 104 | return dateTime.AddTicks(-(dateTime.Ticks % timeSpan.Ticks)); 105 | } 106 | 107 | /// 108 | /// Ignore the Milliseconds Part 109 | /// 110 | /// 111 | /// 112 | public static DateTime IgnoreMilliseconds(this DateTime dateTime) => dateTime.IgnoreTimeSpan(TimeSpan.FromMilliseconds(1000)); 113 | 114 | /// 115 | /// Ignore the Seconds Part 116 | /// 117 | /// 118 | /// 119 | public static DateTime IgnoreSeconds(this DateTime dateTime) => dateTime.IgnoreTimeSpan(TimeSpan.FromSeconds(60)); 120 | 121 | /// 122 | /// Ignore the Minutes Part 123 | /// 124 | /// 125 | /// 126 | public static DateTime IgnoreMinutes(this DateTime dateTime) => dateTime.IgnoreTimeSpan(TimeSpan.FromMinutes(60)); 127 | 128 | /// 129 | /// Ignore the Hours Part 130 | /// 131 | /// 132 | /// 133 | public static DateTime IgnoreHours(this DateTime dateTime) => dateTime.IgnoreTimeSpan(TimeSpan.FromHours(24)); 134 | 135 | /// 136 | /// Is The Date is Sunday? 137 | /// 138 | /// 139 | /// 140 | public static bool IsSunday(this DateTime dateTime) => dateTime.DayOfWeek == DayOfWeek.Sunday; 141 | 142 | /// 143 | /// Is The Date is Moday? 144 | /// 145 | /// 146 | /// 147 | public static bool IsMonday(this DateTime dateTime) => dateTime.DayOfWeek == DayOfWeek.Monday; 148 | 149 | /// 150 | /// Is The Date is Tuesday? 151 | /// 152 | /// 153 | /// 154 | public static bool IsTuesday(this DateTime dateTime) => dateTime.DayOfWeek == DayOfWeek.Tuesday; 155 | 156 | /// 157 | /// Is The Date is Wednesday? 158 | /// 159 | /// 160 | /// 161 | public static bool IsWednesday(this DateTime dateTime) => dateTime.DayOfWeek == DayOfWeek.Wednesday; 162 | 163 | /// 164 | /// Is The Date is Thursday? 165 | /// 166 | /// 167 | /// 168 | public static bool IsThursday(this DateTime dateTime) => dateTime.DayOfWeek == DayOfWeek.Thursday; 169 | 170 | /// 171 | /// Is The Date is Friday? 172 | /// 173 | /// 174 | /// 175 | public static bool IsFriday(this DateTime dateTime) => dateTime.DayOfWeek == DayOfWeek.Friday; 176 | 177 | /// 178 | /// Is The Date is Saturday? 179 | /// 180 | /// 181 | /// 182 | public static bool IsSaturday(this DateTime dateTime) => dateTime.DayOfWeek == DayOfWeek.Saturday; 183 | 184 | /// 185 | /// Last WeekDay in a Year / Month 186 | /// 187 | /// 188 | /// 189 | /// 190 | /// 191 | public static DateTime GetLastWeekdayOfMonth(int year, int month, DayOfWeek day) 192 | { 193 | DateTime lastDayOfTheMonth = new DateTime(year, month, 1) 194 | .AddMonths(1) 195 | .AddDays(-1); 196 | int searchDay = (int)day; 197 | int lastDay = (int)lastDayOfTheMonth.DayOfWeek; 198 | return lastDayOfTheMonth.AddDays(lastDay >= searchDay 199 | ? searchDay - lastDay 200 | : searchDay - lastDay - 7); 201 | } 202 | 203 | /// 204 | /// Generate Date List between two dates 205 | /// 206 | /// 207 | /// 208 | /// 209 | public static List GenerateDateList(DateTime fisrtDate, DateTime lastDate) 210 | { 211 | if (fisrtDate > lastDate) 212 | throw new ArgumentException("Incorrect last date " + lastDate); 213 | 214 | List result = new List(); 215 | for (DateTime day = fisrtDate.Date; day.Date <= lastDate.Date; day = day.AddDays(1)) 216 | { 217 | result.Add(day); 218 | } 219 | 220 | return result; 221 | 222 | } 223 | 224 | /// 225 | /// Return the Date of the first day of week of specific Date 226 | /// 227 | /// 228 | /// 229 | public static DateTime GetFirstDayOfWeek(DateTime dateTime) 230 | { 231 | CultureInfo culture = Thread.CurrentThread.CurrentCulture; 232 | int diff = dateTime.DayOfWeek - culture.DateTimeFormat.FirstDayOfWeek; 233 | 234 | if (diff < 0) 235 | { 236 | diff += 7; 237 | } 238 | 239 | return dateTime.AddDays(-diff).Date; 240 | } 241 | 242 | /// 243 | /// Return the Year's quarter number of specific date 244 | /// 245 | /// 246 | /// 247 | public static int QuarterOfYear(this DateTime dateTime) 248 | { 249 | return dateTime.Month >= 1 && dateTime.Month <= 3 250 | ? 1 251 | : dateTime.Month >= 4 && dateTime.Month <= 6 252 | ? 2 253 | : dateTime.Month >= 7 && dateTime.Month <= 9 254 | ? 3 : 4; 255 | } 256 | 257 | /// 258 | /// Returns Midnight of a DateTime 259 | /// 260 | /// 261 | /// 262 | public static DateTime Midnight(this DateTime dateTime) => dateTime.Date; 263 | 264 | /// 265 | /// Returns the age in years 266 | /// 267 | /// 268 | /// 269 | /// 270 | public static int AgeCalenderYears(DateTime referenceDate, DateTime today) 271 | { 272 | if (referenceDate > today) 273 | throw new ArgumentOutOfRangeException(nameof(referenceDate)); 274 | 275 | return today.Year - referenceDate.Year; 276 | } 277 | 278 | /// 279 | /// Set a Time to a DateTime 280 | /// 281 | /// 282 | /// 283 | /// 284 | /// 285 | /// 286 | public static DateTime SetTime(this DateTime date, int hour = 0, int minute = 0, int second = 0) 287 | { 288 | if (!IsValidTime(hour, minute, second)) 289 | throw new ArgumentOutOfRangeException("Time values are not within ccepted range"); 290 | return new DateTime(date.Year, date.Month, date.Day, hour, minute, second); 291 | } 292 | 293 | /// 294 | /// Return the Date of the last day of week of specific Date 295 | /// 296 | /// 297 | /// 298 | public static DateTime GetLastDayOfWeek(DateTime dateTime) => GetFirstDayOfWeek(dateTime).AddDays(6); 299 | 300 | /// 301 | /// Return the Date of the first day of next week of specific Date 302 | /// 303 | /// 304 | /// 305 | public static DateTime GetFirstDayOfNextWeek(DateTime dateTime) => GetFirstDayOfWeek(dateTime).AddDays(7); 306 | 307 | /// 308 | /// Return the Date of the same day of next month 309 | /// 310 | /// 311 | /// 312 | public static DateTime NextMonthSameDay(this DateTime dateTime) => dateTime.AddMonths(1); 313 | 314 | /// 315 | /// Set a Day to a DateTime 316 | /// 317 | /// 318 | /// 319 | /// 320 | public static DateTime SetDay(this DateTime dateTime, int day) 321 | { 322 | if (!IsValidDate(dateTime.Year, dateTime.Month, day)) 323 | throw new ArgumentOutOfRangeException(nameof(day)); 324 | 325 | return dateTime.AddDays(-1 * dateTime.Day).AddDays(day); 326 | 327 | //return new DateTime(dateTime.Year, dateTime.Month, day, dateTime.Hour, dateTime.Minute, dateTime.Second); 328 | } 329 | 330 | /// 331 | /// Returns same DateTime as Next Year 332 | /// 333 | /// 334 | /// 335 | public static DateTime NextYearSameDay(this DateTime dateTime) => dateTime.AddYears(1); 336 | 337 | /// 338 | /// Returns Noon of a DateTime 339 | /// 340 | /// 341 | /// 342 | public static DateTime Noon(this DateTime dateTime) => dateTime.SetTime(12, 0, 0); 343 | 344 | /// 345 | /// Checks if The DateTime is an AM DateTime value 346 | /// 347 | /// 348 | /// 349 | public static bool IsDateAM(this DateTime dateTime) => dateTime >= dateTime.Midnight() && dateTime < dateTime.Noon(); 350 | 351 | /// 352 | /// Return the Date of the same day of next week 353 | /// 354 | /// 355 | /// 356 | public static DateTime NextWeekSameDay(this DateTime dateTime) => dateTime.AddDays(7); 357 | 358 | /// 359 | /// Return the Year's week number of specific date 360 | /// 361 | /// 362 | /// 363 | public static int WeekOfYear(this DateTime dateTime) 364 | { 365 | int day = (int)dateTime.DayOfWeek; 366 | return CultureInfo.CurrentCulture.Calendar.GetWeekOfYear( 367 | dateTime.AddDays(4 - (day == 0 ? 7 : day)), 368 | CalendarWeekRule.FirstFourDayWeek, 369 | DayOfWeek.Monday); 370 | } 371 | 372 | /// 373 | /// Set a Month to a DateTime 374 | /// 375 | /// 376 | /// 377 | /// 378 | public static DateTime SetMonth(this DateTime dateTime, int month) 379 | { 380 | if (!IsValidDate(dateTime.Year, month, dateTime.Day)) 381 | throw new ArgumentOutOfRangeException("Either month value is not within the range or Month days became out of range"); 382 | 383 | return dateTime.AddMonths(-1 * dateTime.Month).AddMonths(month); 384 | } 385 | 386 | /// 387 | /// Return the Date of the same day of previous week 388 | /// 389 | /// 390 | /// 391 | public static DateTime PreviousWeekSameDay(this DateTime dateTime) => dateTime.AddDays(-7); 392 | 393 | /// 394 | /// First WeekDay in a Year / Month 395 | /// 396 | /// 397 | /// 398 | /// 399 | /// 400 | public static DateTime GetFirstWeekdayOfMonth(int year, int month, DayOfWeek dayOfWeek) 401 | { 402 | return Enumerable.Range(1, 7). 403 | Select(day => new DateTime(year, month, day)). 404 | First(dateTime => (dateTime.DayOfWeek == dayOfWeek)); 405 | } 406 | 407 | /// 408 | /// Returns same DateTime as Previous Year 409 | /// 410 | /// 411 | /// 412 | public static DateTime PreviousYearSameDay(this DateTime dateTime) => dateTime.AddYears(-1); 413 | 414 | 415 | /// 416 | /// Returns the age in years and months 417 | /// 418 | /// 419 | /// 420 | /// 421 | public static int AgeMonths(DateTime referenceDate, DateTime today) 422 | { 423 | if (referenceDate > today) 424 | throw new ArgumentOutOfRangeException(nameof(referenceDate)); 425 | 426 | return (today.Year * 12 + today.Month) - (referenceDate.Year * 12 + referenceDate.Month); 427 | } 428 | 429 | /// 430 | /// Return the Date of the last day of previous week of specific Date 431 | /// 432 | /// 433 | /// 434 | public static DateTime GetLastDayOfPreviousWeek(DateTime dateTime) => GetFirstDayOfWeek(dateTime).AddDays(-1); 435 | 436 | /// 437 | /// Checks if The DateTime is an PM DateTime value 438 | /// 439 | /// 440 | /// 441 | public static bool IsDatePM(this DateTime dateTime) => dateTime >= dateTime.Noon() && dateTime < dateTime.AddDays(1).Midnight(); 442 | 443 | /// 444 | /// Set a Year to a DateTime 445 | /// 446 | /// 447 | /// 448 | /// 449 | public static DateTime SetYear(this DateTime dateTime, int year) 450 | { 451 | if (!IsValidDate(year, dateTime.Month, dateTime.Day)) 452 | throw new ArgumentOutOfRangeException(nameof(dateTime)); 453 | 454 | return new DateTime(year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second) 455 | ; 456 | } 457 | 458 | /// 459 | /// Return the Date of the same day of previous week 460 | /// 461 | /// 462 | /// 463 | public static DateTime PreviousMonthSameDay(this DateTime dateTime) => dateTime.AddMonths(-1); 464 | 465 | /// 466 | /// Returns the age's exact number of years- calulatedfrom exact months 467 | /// 468 | /// 469 | /// 470 | /// 471 | public static decimal AgeExactYears(DateTime referenceDate, DateTime today) 472 | { 473 | if (referenceDate > today) 474 | throw new ArgumentOutOfRangeException(nameof(referenceDate)); 475 | 476 | return Math.Round(((decimal)(today.Year * 12 + today.Month) - (referenceDate.Year * 12 + referenceDate.Month)) / 12, 2); 477 | } 478 | 479 | /// 480 | /// Generate a List of BusinessDays with considering 481 | /// Local Weekend Days Sequence (entered s list) 482 | /// and national holidays (entered as list) 483 | /// 484 | /// 485 | /// 486 | /// 487 | /// Sunday = 0 .. Satuday = 6 488 | /// 489 | public static IEnumerable GenerateBusinessDaysList(DateTime fisrtDate, DateTime lastDate, List holidays, List weekends) 490 | { 491 | if (fisrtDate > lastDate) 492 | throw new ArgumentException("Incorrect last date " + lastDate); 493 | 494 | List result = GenerateDateList(fisrtDate, lastDate); 495 | 496 | foreach (int d in weekends) 497 | { 498 | for (int i = 0; i < result.Count; i++) 499 | { 500 | if ((int)result[i].DayOfWeek == d) 501 | { 502 | result.RemoveAt(i); 503 | } 504 | } 505 | } 506 | 507 | foreach (DateTime d in holidays) 508 | { 509 | for (int i = 0; i < result.Count; i++) 510 | { 511 | if (result[i] == d) 512 | { 513 | result.RemoveAt(i); 514 | } 515 | } 516 | } 517 | 518 | return result.OrderBy(d => d.Date); 519 | } 520 | 521 | /// 522 | /// Returns the DateTime.MaxValue 523 | /// 524 | /// 525 | public static DateTime GetMaxDate() => DateTime.MaxValue; 526 | 527 | } 528 | } 529 | -------------------------------------------------------------------------------- /tests/Aqua.DateTimeHelpers.Tests/DateTimeHelpersTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Xunit; 4 | 5 | namespace Aqua.DateTimeHelpers.Tests 6 | { 7 | public class DateTimeHelpersTests 8 | { 9 | [Theory] 10 | [InlineData(true, 2017, 1, 1)] 11 | [InlineData(false, 2017, 10, 35)] 12 | [InlineData(false, 2017, 13, 1)] 13 | public void IsValidDate_Valid(bool expected, 14 | int year, 15 | int month, 16 | int day) => Assert.Equal(expected, DateTimeHelpers.IsValidDate(year, month, day)); 17 | 18 | [Theory] 19 | [InlineData(true, 23, 30)] 20 | [InlineData(true, 23, 30, 10)] 21 | [InlineData(false, 25, 30, 10)] 22 | [InlineData(false, 23, 65, 10)] 23 | [InlineData(false, 23, 30, 65)] 24 | public void IsValidTime_Valid(bool expected, 25 | int hour, 26 | int minute, 27 | int second = 0) => Assert.Equal(expected, DateTimeHelpers.IsValidTime(hour, minute, second)); 28 | 29 | [Theory] 30 | [InlineData(true, 2017, 1, 1, 22, 30)] 31 | [InlineData(true, 2017, 1, 1, 22, 30, 10)] 32 | [InlineData(false, 2017, 1, 1, 22, 30, 65)] 33 | [InlineData(false, 2017, 10, 35, 10, 10, 10)] 34 | [InlineData(false, 2017, 13, 1, 25, 25, 10)] 35 | public void IsValidDateTime_Valid(bool expected, 36 | int year, 37 | int month, 38 | int day, 39 | int hour, 40 | int minute, 41 | int second = 0) => Assert.Equal(expected, DateTimeHelpers.IsValidDateTime(year, month, day, hour, minute, second)); 42 | 43 | [Theory] 44 | [InlineData(0, 1970, 1, 1, 0, 0, 0)] 45 | [InlineData(86399, 1970, 1, 1, 23, 59, 59)] 46 | [InlineData(1444471810, 2015, 10, 10, 10, 10, 10)] 47 | [InlineData(1433592775, 2015, 6, 6, 12, 12, 55)] 48 | public void UnixTimeStampToDateTime_Valid(long input, 49 | int y, 50 | int m, 51 | int d, 52 | int h, 53 | int mnt, 54 | int s) 55 | { 56 | DateTime mid = new DateTime(y, m, d, h, mnt, s, DateTimeKind.Utc); 57 | DateTime expected = new DateTime(mid.ToLocalTime().Ticks); 58 | 59 | Assert.Equal(expected, DateTimeHelpers.UnixTimeStampToDateTime(input)); 60 | } 61 | 62 | [Theory] 63 | [InlineData(0, 1970, 1, 1, 0, 0, 0)] 64 | [InlineData(86399, 1970, 1, 1, 23, 59, 59)] 65 | [InlineData(1444471810, 2015, 10, 10, 10, 10, 10)] 66 | [InlineData(1433592775, 2015, 6, 6, 12, 12, 55)] 67 | public void UnixTimeStampToDateTimeUTC_Valid(long input, 68 | int y, 69 | int m, 70 | int d, 71 | int h, 72 | int mnt, 73 | int s) 74 | { 75 | DateTime expected = new DateTime(y, m, d, h, mnt, s, DateTimeKind.Utc); 76 | 77 | Assert.Equal(expected, DateTimeHelpers.UnixTimeStampToDateTimeUTC(input)); 78 | } 79 | 80 | [Theory] 81 | [InlineData(0, 1970, 1, 1, 0, 0, 0)] 82 | [InlineData(86399, 1970, 1, 1, 23, 59, 59)] 83 | [InlineData(1444471810, 2015, 10, 10, 10, 10, 10)] 84 | [InlineData(1433592775, 2015, 6, 6, 12, 12, 55)] 85 | public void DateTimeToUnixTimeStamp_Valid(long expected, 86 | int y, 87 | int m, 88 | int d, 89 | int h, 90 | int mnt, 91 | int s) 92 | { 93 | DateTime value = new DateTime(y, m, d, h, mnt, s, DateTimeKind.Utc); 94 | 95 | Assert.Equal(expected, DateTimeHelpers.DateTimeToUnixTimeStamp(value)); 96 | } 97 | 98 | [Theory] 99 | [MemberData(nameof(IsBetweenData))] 100 | public void IsBetween_Valid(bool expected, 101 | DateTime input, 102 | DateTime rangeBegining, 103 | DateTime rangeEnd) => Assert.Equal(expected, input.IsBetween(rangeBegining, rangeEnd)); 104 | 105 | public static IEnumerable IsBetweenData() 106 | { 107 | return new List 108 | { 109 | new object[]{true, new DateTime(2019, 5, 5), new DateTime(2019, 5, 1), new DateTime(2019, 12, 20)}, 110 | new object[]{false, new DateTime(2019, 5, 5), new DateTime(2019, 5, 6), new DateTime(2019, 12, 20)} 111 | }; 112 | } 113 | 114 | [Fact] 115 | public void GetMinDate_Valid() => Assert.Equal(new DateTime(0001, 1, 1), DateTimeHelpers.GetMinDate()); 116 | 117 | [Fact] 118 | public void IgnoreTimeSpan_Valid() 119 | { 120 | Assert.Equal(new DateTime(9999, 12, 31, 23, 59, 59), DateTimeHelpers.IgnoreTimeSpan(DateTime.MaxValue, TimeSpan.FromMilliseconds(1000))); 121 | Assert.Equal(new DateTime(9999, 12, 31, 23, 59, 0), DateTimeHelpers.IgnoreTimeSpan(DateTime.MaxValue, TimeSpan.FromSeconds(60))); 122 | Assert.Equal(new DateTime(9999, 12, 31, 23, 0, 0), DateTimeHelpers.IgnoreTimeSpan(DateTime.MaxValue, TimeSpan.FromMinutes(60))); 123 | Assert.Equal(new DateTime(9999, 12, 31, 0, 0, 0), DateTimeHelpers.IgnoreTimeSpan(DateTime.MaxValue, TimeSpan.FromHours(24))); 124 | } 125 | 126 | [Fact] 127 | public void IgnoreMilliseconds_Valid() => Assert.Equal(new DateTime(9999, 12, 31, 23, 59, 59), DateTime.MaxValue.IgnoreMilliseconds()); 128 | 129 | [Fact] 130 | public void IgnoreSeconds_Valid() => Assert.Equal(new DateTime(9999, 12, 31, 23, 59, 0), DateTime.MaxValue.IgnoreSeconds()); 131 | 132 | [Fact] 133 | public void IgnoreMinutes_Valid() => Assert.Equal(new DateTime(9999, 12, 31, 23, 0, 0), DateTime.MaxValue.IgnoreMinutes()); 134 | 135 | [Fact] 136 | public void IgnoreHours_Valid() => Assert.Equal(new DateTime(9999, 12, 31, 0, 0, 0), DateTime.MaxValue.IgnoreHours()); 137 | 138 | [Theory] 139 | [InlineData(true, 2019, 2, 10)] 140 | [InlineData(true, 2017, 10, 15)] 141 | [InlineData(false, 2019, 8, 15)] 142 | public void IsSunday_Valid(bool expected, 143 | int year, 144 | int month, 145 | int day) => Assert.Equal(expected, DateTimeHelpers.IsSunday(new DateTime(year, month, day))); 146 | 147 | [Theory] 148 | [InlineData(false, 2019, 2, 10)] 149 | [InlineData(false, 2017, 10, 15)] 150 | [InlineData(true, 2019, 8, 12)] 151 | public void IsMonday_Valid(bool expected, 152 | int year, 153 | int month, 154 | int day) => Assert.Equal(expected, DateTimeHelpers.IsMonday(new DateTime(year, month, day))); 155 | 156 | [Theory] 157 | [InlineData(false, 2019, 2, 10)] 158 | [InlineData(false, 2017, 10, 15)] 159 | [InlineData(true, 2019, 8, 13)] 160 | public void IsTuesday_Valid(bool expected, 161 | int year, 162 | int month, 163 | int day) => Assert.Equal(expected, DateTimeHelpers.IsTuesday(new DateTime(year, month, day))); 164 | 165 | [Theory] 166 | [InlineData(false, 2019, 2, 10)] 167 | [InlineData(false, 2017, 10, 15)] 168 | [InlineData(true, 2019, 8, 14)] 169 | public void IsWednesday_Valid(bool expected, 170 | int year, 171 | int month, 172 | int day) => Assert.Equal(expected, DateTimeHelpers.IsWednesday(new DateTime(year, month, day))); 173 | 174 | [Theory] 175 | [InlineData(false, 2019, 2, 10)] 176 | [InlineData(false, 2017, 10, 15)] 177 | [InlineData(true, 2019, 8, 15)] 178 | public void IsThursday_Valid(bool expected, 179 | int year, 180 | int month, 181 | int day) => Assert.Equal(expected, DateTimeHelpers.IsThursday(new DateTime(year, month, day))); 182 | 183 | [Theory] 184 | [InlineData(false, 2019, 2, 10)] 185 | [InlineData(false, 2017, 10, 15)] 186 | [InlineData(true, 2019, 8, 16)] 187 | public void IsFriday_Valid(bool expected, 188 | int year, 189 | int month, 190 | int day) => Assert.Equal(expected, DateTimeHelpers.IsFriday(new DateTime(year, month, day))); 191 | 192 | [Theory] 193 | [InlineData(false, 2019, 2, 10)] 194 | [InlineData(false, 2017, 10, 15)] 195 | [InlineData(true, 2019, 8, 17)] 196 | public void IsSaturday_Valid(bool expected, 197 | int year, 198 | int month, 199 | int day) => Assert.Equal(expected, DateTimeHelpers.IsSaturday(new DateTime(year, month, day))); 200 | 201 | [Theory] 202 | [MemberData(nameof(GetLastWeekdayOfMonthData))] 203 | public void GetLastWeekdayOfMonth_Valid(DateTime expected, int year, int month, DayOfWeek day) => Assert.Equal(expected, DateTimeHelpers.GetLastWeekdayOfMonth(year, month, day)); 204 | 205 | public static IEnumerable GetLastWeekdayOfMonthData => 206 | new List 207 | { 208 | new object[]{new DateTime(2019, 8, 25), 2019, 8, DayOfWeek.Sunday}, 209 | new object[]{new DateTime(2019, 8, 30), 2019, 8, DayOfWeek.Friday}, 210 | }; 211 | 212 | [Theory] 213 | [MemberData(nameof(GenerateDateListData))] 214 | public void GenerateDateList_Valid(IEnumerable expected, 215 | DateTime fisrtDate, 216 | DateTime lastDate) => Assert.Equal(expected, DateTimeHelpers.GenerateDateList(fisrtDate, lastDate)); 217 | 218 | public static IEnumerable GenerateDateListData() 219 | { 220 | return new List 221 | { 222 | // DaysOfWeek Int Sunday = 0, Monday = 1 ... Saturday = 6 223 | new object[]{new List { new DateTime (2019, 1, 2) , new DateTime (2019, 1, 3) , new DateTime (2019, 1, 4), new DateTime(2019, 1, 5) } , 224 | new DateTime (2019, 1, 2), new DateTime (2019, 1, 5), 225 | }, 226 | new object[]{new List { new DateTime(2019, 5, 27), new DateTime (2019, 5, 28) , new DateTime (2019, 5, 29) , new DateTime (2019, 5, 30) , new DateTime (2019, 5, 31), new DateTime(2019, 6, 1), new DateTime(2019, 6, 2) } , 227 | new DateTime (2019, 5, 27), new DateTime (2019, 6, 2), 228 | } 229 | }; 230 | } 231 | 232 | [Theory(Skip = "culture difference")] 233 | [MemberData(nameof(GetFirstDayOfWeekData))] 234 | public void GetFirstDayOfWeek_Valid(DateTime expected, 235 | DateTime dateTime) => Assert.Equal(expected, DateTimeHelpers.GetFirstDayOfWeek(dateTime)); 236 | 237 | public static IEnumerable GetFirstDayOfWeekData => 238 | new List 239 | { 240 | new object[]{new DateTime(2019, 4, 29), new DateTime(2019, 5, 4)}, 241 | new object[]{new DateTime(2019, 4, 29), new DateTime(2019, 5, 2)}, 242 | }; 243 | 244 | [Fact] 245 | public void QuarterOfYear_Valid() 246 | { 247 | Assert.Equal(1, (new DateTime(2019, 2, 25)).QuarterOfYear()); 248 | Assert.Equal(2, (new DateTime(2019, 6, 20)).QuarterOfYear()); 249 | Assert.Equal(3, (new DateTime(2019, 7, 25)).QuarterOfYear()); 250 | Assert.Equal(4, (new DateTime(2019, 10, 25)).QuarterOfYear()); 251 | } 252 | 253 | [Fact] 254 | public void Midnight_Valid() 255 | { 256 | Assert.Equal(new DateTime(2019, 12, 25), (new DateTime(2019, 12, 25, 1, 0, 0)).Midnight()); 257 | Assert.Equal(new DateTime(2019, 12, 25), (new DateTime(2019, 12, 25, 1, 10, 0)).Midnight()); 258 | Assert.Equal(new DateTime(2019, 12, 25), (new DateTime(2019, 12, 25, 1, 10, 55)).Midnight()); 259 | } 260 | 261 | [Fact] 262 | public void AgeYears_Valid() => Assert.Equal(40, DateTimeHelpers.AgeCalenderYears(new DateTime(1980, 8, 10, 13, 0, 0), new DateTime(2020, 5, 5))); 263 | 264 | [Fact] 265 | public void SetTime_Valid() 266 | { 267 | Assert.Equal(new DateTime(2019, 12, 25), (new DateTime(2019, 12, 25)).SetTime()); 268 | Assert.Equal(new DateTime(2019, 12, 25, 1, 0, 0), (new DateTime(2019, 12, 25)).SetTime(1)); 269 | Assert.Equal(new DateTime(2019, 12, 25, 1, 10, 0), (new DateTime(2019, 12, 25)).SetTime(1, 10)); 270 | Assert.Equal(new DateTime(2019, 12, 25, 1, 10, 55), (new DateTime(2019, 12, 25)).SetTime(1, 10, 55)); 271 | } 272 | 273 | [Theory(Skip = "culture difference")] 274 | [MemberData(nameof(GetLastDayOfWeekData))] 275 | public void GetLastDayOfWeek_Valid(DateTime expected, DateTime dateTime) => Assert.Equal(expected, DateTimeHelpers.GetLastDayOfWeek(dateTime)); 276 | 277 | public static IEnumerable GetLastDayOfWeekData => 278 | new List 279 | { 280 | new object[]{new DateTime(2019, 5, 5), new DateTime(2019, 5, 4)}, 281 | new object[]{new DateTime(2019, 5, 5), new DateTime(2019, 5, 2)}, 282 | }; 283 | 284 | [Theory(Skip = "culture difference")] 285 | [MemberData(nameof(GetFirstDayOfNextWeekData))] 286 | public void GetFirstDayOfNextWeek_Valid(DateTime expected, 287 | DateTime dateTime) => Assert.Equal(expected, DateTimeHelpers.GetFirstDayOfNextWeek(dateTime)); 288 | 289 | public static IEnumerable GetFirstDayOfNextWeekData => 290 | new List 291 | { 292 | new object[]{new DateTime(2019, 8, 5), new DateTime(2019, 8, 4)}, 293 | new object[]{new DateTime(2019, 8, 5), new DateTime(2019, 8, 2)}, 294 | }; 295 | 296 | [Fact] 297 | public void NextMonthSameDay_Valid() 298 | { 299 | Assert.Equal(new DateTime(2019, 8, 17), (new DateTime(2019, 7, 17)).NextMonthSameDay()); 300 | Assert.Equal(new DateTime(2019, 7, 3), (new DateTime(2019, 6, 3)).NextMonthSameDay()); 301 | } 302 | 303 | [Fact] 304 | public void SetDay_Valid() 305 | { 306 | Assert.Equal(new DateTime(2019, 12, 20), (new DateTime(2019, 12, 25)).SetDay(20)); 307 | Assert.Equal(new DateTime(2019, 12, 20, 1, 0, 0), (new DateTime(2019, 12, 25, 1, 0, 0)).SetDay(20)); 308 | Assert.Equal(new DateTime(2019, 12, 20, 1, 10, 0), (new DateTime(2019, 12, 25, 1, 10, 0)).SetDay(20)); 309 | Assert.Equal(new DateTime(2019, 12, 20, 1, 10, 55), (new DateTime(2019, 12, 25, 1, 10, 55)).SetDay(20)); 310 | } 311 | 312 | [Fact] 313 | public void NextYearSameDay_Valid() 314 | { 315 | Assert.Equal(new DateTime(2020, 12, 25), (new DateTime(2019, 12, 25)).NextYearSameDay()); 316 | Assert.Equal(new DateTime(2020, 12, 25, 1, 0, 0), (new DateTime(2019, 12, 25, 1, 0, 0)).NextYearSameDay()); 317 | Assert.Equal(new DateTime(2020, 12, 25, 1, 10, 0), (new DateTime(2019, 12, 25, 1, 10, 0)).NextYearSameDay()); 318 | Assert.Equal(new DateTime(2020, 12, 25, 1, 10, 55), (new DateTime(2019, 12, 25, 1, 10, 55)).NextYearSameDay()); 319 | } 320 | 321 | [Fact] 322 | public void Noon_Valid() 323 | { 324 | Assert.Equal(new DateTime(2019, 12, 25, 12, 0, 0), (new DateTime(2019, 12, 25, 1, 0, 0)).Noon()); 325 | Assert.Equal(new DateTime(2019, 12, 25, 12, 0, 0), (new DateTime(2019, 12, 25, 1, 10, 0)).Noon()); 326 | Assert.Equal(new DateTime(2019, 12, 25, 12, 0, 0), (new DateTime(2019, 12, 25, 1, 10, 55)).Noon()); 327 | } 328 | 329 | [Fact] 330 | public void IsDayAM_Valid() 331 | { 332 | Assert.True(new DateTime(2019, 12, 25, 1, 10, 50).IsDateAM()); 333 | Assert.False(new DateTime(2019, 12, 25, 15, 10, 50).IsDateAM()); 334 | Assert.True(new DateTime(2019, 12, 25, 10, 10, 55).IsDateAM()); 335 | } 336 | 337 | [Fact] 338 | public void NextWeekSameDay_Valid() 339 | { 340 | Assert.Equal(new DateTime(2019, 7, 24), (new DateTime(2019, 7, 17)).NextWeekSameDay()); 341 | Assert.Equal(new DateTime(2019, 6, 10), (new DateTime(2019, 6, 3)).NextWeekSameDay()); 342 | } 343 | 344 | [Fact] 345 | public void WeekOfYear_Valid() 346 | { 347 | Assert.Equal(9, (new DateTime(2019, 2, 25)).WeekOfYear()); 348 | Assert.Equal(3, (new DateTime(2019, 1, 20)).WeekOfYear()); 349 | Assert.Equal(52, (new DateTime(2019, 12, 25)).WeekOfYear()); 350 | } 351 | 352 | [Fact] 353 | public void SetMonth_Valid() 354 | { 355 | Assert.Equal(new DateTime(2019, 5, 25), (new DateTime(2019, 12, 25)).SetMonth(5)); 356 | Assert.Equal(new DateTime(2019, 5, 25, 1, 0, 0), (new DateTime(2019, 12, 25, 1, 0, 0)).SetMonth(5)); 357 | Assert.Equal(new DateTime(2019, 5, 25, 1, 10, 0), (new DateTime(2019, 12, 25, 1, 10, 0)).SetMonth(5)); 358 | Assert.Equal(new DateTime(2019, 5, 25, 1, 10, 55), (new DateTime(2019, 12, 25, 1, 10, 55)).SetMonth(5)); 359 | } 360 | 361 | [Fact] 362 | public void PreviousWeekSameDay_Valid() 363 | { 364 | Assert.Equal(new DateTime(2019, 6, 30), (new DateTime(2019, 7, 7)).PreviousWeekSameDay()); 365 | Assert.Equal(new DateTime(2019, 5, 27), (new DateTime(2019, 6, 3)).PreviousWeekSameDay()); 366 | } 367 | 368 | [Theory] 369 | [MemberData(nameof(GetFirstWeekdayOfMonthData))] 370 | public void GetFirstWeekdayOfMonth_Valid(DateTime expected, 371 | int year, 372 | int month, 373 | DayOfWeek day) => Assert.Equal(expected, DateTimeHelpers.GetFirstWeekdayOfMonth(year, month, day)); 374 | 375 | public static IEnumerable GetFirstWeekdayOfMonthData => 376 | new List 377 | { 378 | new object[]{new DateTime(2019, 8, 4), 2019, 8, DayOfWeek.Sunday}, 379 | new object[]{new DateTime(2019, 8, 2), 2019, 8, DayOfWeek.Friday}, 380 | }; 381 | 382 | [Fact] 383 | public void PreviousYearSameDay_Valid() 384 | { 385 | Assert.Equal(new DateTime(2018, 12, 25), (new DateTime(2019, 12, 25)).PreviousYearSameDay()); 386 | Assert.Equal(new DateTime(2018, 12, 25, 1, 0, 0), (new DateTime(2019, 12, 25, 1, 0, 0)).PreviousYearSameDay()); 387 | Assert.Equal(new DateTime(2018, 12, 25, 1, 10, 0), (new DateTime(2019, 12, 25, 1, 10, 0)).PreviousYearSameDay()); 388 | Assert.Equal(new DateTime(2018, 12, 25, 1, 10, 55), (new DateTime(2019, 12, 25, 1, 10, 55)).PreviousYearSameDay()); 389 | } 390 | 391 | [Fact] 392 | public void AgeMonths_Valid() => Assert.Equal(477, DateTimeHelpers.AgeMonths(new DateTime(1980, 8, 10, 13, 0, 0), new DateTime(2020, 5, 5))); 393 | 394 | [Theory(Skip = "culture difference")] 395 | [MemberData(nameof(GetLastDayOfPreviousWeekData))] 396 | public void GetLastDayOfPreviousWeek_Valid(DateTime expected, DateTime dateTime) => Assert.Equal(expected, DateTimeHelpers.GetLastDayOfPreviousWeek(dateTime)); 397 | 398 | public static IEnumerable GetLastDayOfPreviousWeekData => 399 | new List 400 | { 401 | new object[]{new DateTime(2019, 7, 28), new DateTime(2019, 8, 4)}, 402 | new object[]{new DateTime(2019, 7, 28), new DateTime(2019, 8, 2)}, 403 | }; 404 | 405 | [Fact] 406 | public void IsDayPM_Valid() 407 | { 408 | Assert.False(new DateTime(2019, 12, 25, 1, 10, 50).IsDatePM()); 409 | Assert.True(new DateTime(2019, 12, 25, 15, 10, 50).IsDatePM()); 410 | Assert.False(new DateTime(2019, 12, 25, 10, 10, 55).IsDatePM()); 411 | } 412 | 413 | [Fact] 414 | public void SetYear_Valid() 415 | { 416 | Assert.Equal(new DateTime(2020, 12, 25), (new DateTime(2019, 12, 25)).SetYear(2020)); 417 | Assert.Equal(new DateTime(2020, 12, 25, 1, 0, 0), (new DateTime(2019, 12, 25, 1, 0, 0)).SetYear(2020)); 418 | Assert.Equal(new DateTime(2020, 12, 25, 1, 10, 0), (new DateTime(2019, 12, 25, 1, 10, 0)).SetYear(2020)); 419 | Assert.Equal(new DateTime(2020, 12, 25, 1, 10, 55), (new DateTime(2019, 12, 25, 1, 10, 55)).SetYear(2020)); 420 | } 421 | 422 | [Fact] 423 | public void PreviousMonthSameDay_Valid() 424 | { 425 | Assert.Equal(new DateTime(2019, 6, 7), (new DateTime(2019, 7, 7)).PreviousMonthSameDay()); 426 | Assert.Equal(new DateTime(2019, 5, 3), (new DateTime(2019, 6, 3)).PreviousMonthSameDay()); 427 | } 428 | 429 | [Fact] 430 | public void AgeExactYears_Valid() => Assert.Equal((decimal)39.75, DateTimeHelpers.AgeExactYears(new DateTime(1980, 8, 10, 13, 0, 0), new DateTime(2020, 5, 5))); 431 | 432 | [Theory] 433 | [MemberData(nameof(GenerateBusinessDaysListData))] 434 | public void GenerateBusinessDaysList_Valid(IEnumerable expected, DateTime fisrtDate, DateTime lastDate, List holidays, List weekends) => Assert.Equal(expected, DateTimeHelpers.GenerateBusinessDaysList(fisrtDate, lastDate, holidays, weekends)); 435 | 436 | public static IEnumerable GenerateBusinessDaysListData() 437 | { 438 | return new List 439 | { 440 | // DaysOfWeek Int Sunday = 0, Monday = 1 ... Saturday = 6 441 | new object[]{new List { new DateTime (2019, 1, 2) , new DateTime (2019, 1, 3) , new DateTime (2019, 1, 4)} , 442 | new DateTime (2019, 1, 2), new DateTime (2019, 1, 5), 443 | new List { new DateTime (2019, 1, 1) , new DateTime (2019, 4, 19) , new DateTime (2019, 4, 22) , new DateTime (2019, 5, 6) , new DateTime(2019, 5, 27), new DateTime(2019, 8, 26), new DateTime(2019, 12, 25), new DateTime(2019, 12, 26) } , 444 | new List {6,0} 445 | }, 446 | new object[]{new List { new DateTime (2019, 5, 28) , new DateTime (2019, 5, 29) , new DateTime (2019, 5, 30) , new DateTime (2019, 5, 31)} , 447 | new DateTime (2019, 5, 27), new DateTime (2019, 6, 2), 448 | new List { new DateTime (2019, 1, 1) , new DateTime (2019, 4, 19) , new DateTime (2019, 4, 22) , new DateTime (2019, 5, 6) , new DateTime(2019, 5, 27), new DateTime(2019, 8, 26), new DateTime(2019, 12, 25), new DateTime(2019, 12, 26) } , 449 | new List {6,0} 450 | 451 | } 452 | }; 453 | } 454 | 455 | [Fact] 456 | public void GetMaxDate_Valid() => Assert.Equal((new DateTime(9999, 12, 31, 23, 59, 59)).IgnoreMilliseconds(), DateTimeHelpers.GetMaxDate().IgnoreMilliseconds()); 457 | } 458 | } 459 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build status](https://ci.appveyor.com/api/projects/status/l530thr4ji3vy5ka?svg=true)](https://ci.appveyor.com/project/ualehosaini/aqua-datetimehelpers) 2 | [![NuGet Version](https://img.shields.io/nuget/v/Aqua.DateTimeHelpers.svg)](https://www.nuget.org/packages/Aqua.DateTimeHelpers/) 3 | 4 | # About Aqua DateTime Helpers: 5 | 6 | Aqua DateTime Helpers is an Open Source and Free Software package consists of a set of utilities that facilitate the job of the developer and save his time while dealing with a string. Every developer could be a beneficiary of this library; however, those who deal with database and integration applications are likely the most potential beneficiaries. 7 | 8 | 9 | # Getting Started 10 | TODO: Guide users through getting your code up and running on their own system. In this section you can talk about: 11 | 1. Installation process 12 | 2. Software dependencies 13 | 3. Latest releases 14 | 4. API references 15 | 16 | # List of Features and Methods 17 | 1. [IsValidDate](#IsValidDate) 18 | 2. [IsValidTime](#IsValidTime) 19 | 3. [IsValidDateTime](#IsValidDateTime) 20 | 4. [IsBetween](#IsBetween) 21 | 5. [IgnoreTimeSpan](#IgnoreTimeSpan) 22 | 6. [IgnoreMilliseconds](#IgnoreMilliseconds) 23 | 7. [IgnoreSeconds](#IgnoreSeconds) 24 | 8. [IgnoreMinutes](#IgnoreMinutes) 25 | 9. [IgnoreHours](#IgnoreHours) 26 | 10. [GetMinDate](#GetMinDate) 27 | 11. [GetMaxDate](#GetMaxDate) 28 | 12. [UnixTimeStampToDateTime](#UnixTimeStampToDateTime) 29 | 13. [UnixTimeStampToDateTimeUTC](#UnixTimeStampToDateTimeUTC) 30 | 14. [DateTimeToUnixTimeStamp](#DateTimeToUnixTimeStamp) 31 | 15. [IsSunday](#IsSunday) 32 | 16. [IsMonday](#IsMonday) 33 | 17. [IsTuesday](#IsTuesday) 34 | 18. [IsWednesday](#IsWednesday) 35 | 19. [IsThursday](#IsThursday) 36 | 20. [IsFriday](#IsFriday) 37 | 21. [IsSaturday](#IsSaturday) 38 | 22. [IsDateAM](#IsDateAM) 39 | 23. [IsDatePM](#IsDatePM) 40 | 24. [GenerateDateList](#GenerateDateList) 41 | 25. [GenerateBusinessDaysList](#GenerateBusinessDaysList) 42 | 26. [GetLastWeekdayOfMonth](#GetLastWeekdayOfMonth) 43 | 27. [GetFirstWeekdayOfMonth](#GetFirstWeekdayOfMonth) 44 | 28. [GetFirstDayOfWeek](#GetFirstDayOfWeek) 45 | 29. [GetLastDayOfWeek](#GetLastDayOfWeek) 46 | 30. [GetLastDayOfPreviousWeek](#GetLastDayOfPreviousWeek) 47 | 31. [GetFirstDayOfNextWeek](#GetFirstDayOfNextWeek) 48 | 32. [NextWeekSameDay](#NextWeekSameDay) 49 | 33. [PreviousWeekSameDay](#PreviousWeekSameDay) 50 | 34. [NextMonthSameDay](#NextMonthSameDay) 51 | 35. [PreviousMonthSameDay](#PreviousMonthSameDay) 52 | 36. [QuarterOfYear](#QuarterOfYear) 53 | 37. [WeekOfYear](#WeekOfYear) 54 | 38. [Midnight](#Midnight) 55 | 39. [Noon](#Noon) 56 | 40. [NextYearSameDay](#NextYearSameDay) 57 | 41. [PreviousYearSameDay](#PreviousYearSameDay) 58 | 42. [AgeCalenderYears](#AgeCalenderYears) 59 | 43. [AgeMonths](#AgeMonths) 60 | 44. [AgeExactYears](#AgeExactYears) 61 | 45. [SetTime](#SetTime) 62 | 46. [SetDay](#SetDay) 63 | 47. [SetMonth](#SetMonth) 64 | 48. [SetYear](#SetYear) 65 | 66 | # Features and Methods 67 | 68 | ### IsValidDate 69 | ```C# 70 | //using Aqua.DateTimeHelpers; 71 | 72 | int year; 73 | int month; 74 | int day; 75 | bool output; 76 | 77 | year = 2019; 78 | month = 10; 79 | day = 15; 80 | output = DateTimeHelpers.IsValidDate(year, month, day); // output = true 81 | 82 | year = 2019; 83 | month = 15; 84 | day = 15; 85 | output = DateTimeHelpers.IsValidDate(year, month, day); // output = false 86 | 87 | year = 2019; 88 | month = 10; 89 | day = 35; 90 | output = DateTimeHelpers.IsValidDate(year, month, day); // output = false 91 | 92 | ``` 93 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 94 | 95 | ### IsValidTime 96 | ```C# 97 | //using Aqua.DateTimeHelpers; 98 | 99 | int hour; 100 | int minute; 101 | int second; 102 | bool output; 103 | 104 | hour = 10; 105 | minute = 35; 106 | second = 59; 107 | output = DateTimeHelpers.IsValidTime(hour, minute, second); // output = true 108 | 109 | hour = 35; 110 | minute = 35; 111 | second = 59; 112 | output = DateTimeHelpers.IsValidTime(hour, minute, second); // output = false 113 | 114 | hour = 10; 115 | minute = 35; 116 | second = 59; 117 | output = DateTimeHelpers.IsValidTime(hour, minute, second); // output = false 118 | 119 | ``` 120 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 121 | 122 | ### IsValidDateTime 123 | ```C# 124 | //using Aqua.DateTimeHelpers; 125 | 126 | int year; 127 | int month; 128 | int day; 129 | int hour; 130 | int minute; 131 | int second; 132 | bool output; 133 | 134 | year = 2019; 135 | month = 10; 136 | day = 15; 137 | hour = 10; 138 | minute = 35; 139 | second = 59; 140 | output = DateTimeHelpers.IsValidDateTime(year, month, day, hour, minute, second); // output = true 141 | 142 | year = 2019; 143 | month = 15; 144 | day = 15; 145 | hour = 35; 146 | minute = 35; 147 | second = 59; 148 | output = DateTimeHelpers.IsValidDateTime(year, month, day, hour, minute, second); // output = false 149 | 150 | year = 2019; 151 | month = 10; 152 | day = 35; 153 | hour = 10; 154 | minute = 35; 155 | second = 59; 156 | output = DateTimeHelpers.IsValidDateTime(year, month, day, hour, minute, second); // output = false 157 | 158 | ``` 159 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 160 | 161 | ### IsBetween 162 | ```C# 163 | //using Aqua.DateTimeHelpers; 164 | 165 | DateTime input; 166 | DateTime rangeStart; 167 | DateTime rangeEnd; 168 | bool output; 169 | 170 | input = new DateTime(2019, 9, 9); 171 | rangeStart = new DateTime(2018, 9, 9); 172 | rangeEnd = new DateTime(2019, 9, 10); 173 | output = input.IsBetween(rangeStart, rangeEnd); // output = true 174 | 175 | input = new DateTime(2019, 9, 9, 10, 10, 57); 176 | rangeStart = new DateTime(2019, 9, 9, 10, 10, 55); 177 | rangeEnd = new DateTime(2019, 9, 9, 10, 10, 56); 178 | output = input.IsBetween(rangeStart, rangeEnd); // output = false 179 | 180 | input = new DateTime(2019, 9, 9, 10, 10, 57); 181 | rangeStart = new DateTime(2019, 9, 9, 10, 10, 56); 182 | rangeEnd = new DateTime(2019, 9, 10, 10, 10, 58); 183 | output = input.IsBetween(rangeStart, rangeEnd); // output = true 184 | ``` 185 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 186 | 187 | ### IgnoreTimeSpan 188 | ```C# 189 | //using Aqua.DateTimeHelpers; 190 | 191 | DateTime input; 192 | TimeSpan toBeIgnored; 193 | DateTime output; 194 | 195 | input = new DateTime(2019, 9, 9, 10, 10, 10, 765); 196 | toBeIgnored = TimeSpan.FromMilliseconds(1000); 197 | output = input.IgnoreTimeSpan(toBeIgnored); // output = "09/09/2019 10:10:10" 198 | 199 | input = new DateTime(2019, 9, 9, 10, 10, 10, 999); 200 | toBeIgnored = TimeSpan.FromSeconds(55); 201 | output = input.IgnoreTimeSpan(toBeIgnored); // output = "09/09/2019 10:09:45" 202 | 203 | input = new DateTime(2019, 9, 9, 10, 10, 10, 222); 204 | toBeIgnored = TimeSpan.FromMinutes(60); 205 | output = input.IgnoreTimeSpan(toBeIgnored); // output = "09/09/2019 10:00:00" 206 | 207 | ``` 208 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 209 | 210 | ### IgnoreMilliseconds 211 | ```C# 212 | //using Aqua.DateTimeHelpers; 213 | 214 | DateTime input; 215 | DateTime output; 216 | 217 | input = new DateTime(2019, 9, 9, 10, 10, 10, 765); 218 | output = input.IgnoreMilliseconds(); // output = "09/09/2019 10:10:10" 219 | 220 | input = new DateTime(2019, 9, 9, 10, 10, 10, 999); 221 | output = input.IgnoreMilliseconds(); // output = "09/09/2019 10:10:10" 222 | 223 | input = new DateTime(2019, 9, 9, 10, 10, 10, 222); 224 | output = input.IgnoreMilliseconds(); // output = "09/09/2019 10:10:10" 225 | 226 | ``` 227 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 228 | 229 | ### IgnoreSeconds 230 | ```C# 231 | //using Aqua.DateTimeHelpers; 232 | 233 | DateTime input; 234 | DateTime output; 235 | 236 | input = new DateTime(2019, 9, 9, 10, 10, 10, 765); 237 | output = input.IgnoreSeconds(); // output = "09/09/2019 10:10:00" 238 | 239 | input = new DateTime(2019, 9, 9, 10, 10, 15, 999); 240 | output = input.IgnoreSeconds(); // output = "09/09/2019 10:10:00" 241 | 242 | input = new DateTime(2019, 9, 9, 10, 10, 55, 222); 243 | output = input.IgnoreSeconds(); // output = "09/09/2019 10:10:00" 244 | ``` 245 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 246 | 247 | ### IgnoreMinutes 248 | ```C# 249 | //using Aqua.DateTimeHelpers; 250 | 251 | DateTime input; 252 | DateTime output; 253 | 254 | input = new DateTime(2019, 9, 9, 10, 10, 10, 765); 255 | output = input.IgnoreMinutes(); // output = "09/09/2019 10:00:00" 256 | 257 | input = new DateTime(2019, 9, 9, 10, 55, 10, 999); 258 | output = input.IgnoreMinutes(); // output = "09/09/2019 10:00:00" 259 | 260 | input = new DateTime(2019, 9, 9, 10, 44, 10, 222); 261 | output = input.IgnoreMinutes(); // output = "09/09/2019 10:00:00" 262 | ``` 263 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 264 | 265 | ### IgnoreHours 266 | ```C# 267 | //using Aqua.DateTimeHelpers; 268 | 269 | DateTime input; 270 | DateTime output; 271 | 272 | input = new DateTime(2019, 9, 9, 10, 10, 10, 765); 273 | output = input.IgnoreHours(); // output = "09/09/2019 00:00:00" 274 | 275 | input = new DateTime(2019, 9, 9, 17, 55, 10, 999); 276 | output = input.IgnoreHours(); // output = "09/09/2019 00:00:00" 277 | 278 | input = new DateTime(2019, 9, 9, 23, 44, 10, 222); 279 | output = input.IgnoreHours(); // output = "09/09/2019 00:00:00" 280 | ``` 281 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 282 | 283 | ### GetMinDate 284 | ```C# 285 | //using Aqua.DateTimeHelpers; 286 | 287 | DateTime output; 288 | 289 | output = DateTimeHelpers.GetMinDate(); //output = "01/01/0001 00:00:00" 290 | ``` 291 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 292 | 293 | ### GetMaxDate 294 | ```C# 295 | //using Aqua.DateTimeHelpers; 296 | 297 | DateTime output; 298 | 299 | output = DateTimeHelpers.GetMaxDate(); //output = "31/12/9999 23:59:59" 300 | ``` 301 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 302 | 303 | ### UnixTimeStampToDateTime 304 | ```C# 305 | //using Aqua.DateTimeHelpers; 306 | 307 | DateTime output; 308 | 309 | output = DateTimeHelpers.UnixTimeStampToDateTime(78787878); //output = "30/06/1972 22:31:18" 310 | ``` 311 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 312 | 313 | ### UnixTimeStampToDateTimeUTC 314 | ```C# 315 | //using Aqua.DateTimeHelpers; 316 | 317 | DateTime output; 318 | 319 | output = DateTimeHelpers.UnixTimeStampToDateTimeUTC(787878788); //output = "19/12/1994 23:13:08" 320 | ``` 321 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 322 | 323 | ### DateTimeToUnixTimeStamp 324 | ```C# 325 | //using Aqua.DateTimeHelpers; 326 | 327 | DateTime input = new DateTime(1994, 12, 19, 23, 13, 08); 328 | 329 | double output; 330 | 331 | output = DateTimeHelpers.DateTimeToUnixTimeStamp(input); //output = 787878788 332 | ``` 333 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 334 | 335 | ### IsSunday 336 | ```C# 337 | //using Aqua.DateTimeHelpers; 338 | 339 | DateTime input; 340 | bool output; 341 | 342 | input = new DateTime(1994, 12, 19, 23, 13, 08); 343 | 344 | output = input.IsSunday(); //output = false 345 | 346 | input = new DateTime(2019, 7, 14, 23, 13, 08); 347 | 348 | output = input.IsSunday(); //output = true 349 | 350 | input = new DateTime(2019, 7, 21); 351 | 352 | output = input.IsSunday(); //output = true 353 | ``` 354 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 355 | 356 | ### IsMonday 357 | ```C# 358 | //using Aqua.DateTimeHelpers; 359 | 360 | DateTime input; 361 | bool output; 362 | 363 | input = new DateTime(1994, 12, 18, 22, 13, 08); 364 | 365 | output = input.IsMonday(); //output = false 366 | 367 | input = new DateTime(2019, 7, 15, 20, 13, 08); 368 | 369 | output = input.IsMonday(); //output = true 370 | 371 | input = new DateTime(2019, 7, 22); 372 | 373 | output = input.IsMonday(); //output = true 374 | ``` 375 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 376 | 377 | ### IsTuesday 378 | ```C# 379 | //using Aqua.DateTimeHelpers; 380 | 381 | DateTime input; 382 | bool output; 383 | 384 | input = new DateTime(1994, 12, 19, 22, 13, 08); 385 | 386 | output = input.IsTuesday(); //output = false 387 | 388 | input = new DateTime(2019, 7, 16, 20, 13, 08); 389 | 390 | output = input.IsTuesday(); //output = true 391 | 392 | input = new DateTime(2019, 7, 23); 393 | 394 | output = input.IsTuesday(); //output = true 395 | ``` 396 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 397 | 398 | ### IsWednesday 399 | ```C# 400 | //using Aqua.DateTimeHelpers; 401 | 402 | DateTime input; 403 | bool output; 404 | 405 | input = new DateTime(1994, 12, 20, 22, 13, 08); 406 | 407 | output = input.IsWednesday(); //output = false 408 | 409 | input = new DateTime(2019, 7, 17, 20, 13, 08); 410 | 411 | output = input.IsWednesday(); //output = true 412 | 413 | input = new DateTime(2019, 7, 24); 414 | 415 | output = input.IsWednesday(); //output = true 416 | ``` 417 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 418 | 419 | ### IsThursday 420 | ```C# 421 | //using Aqua.DateTimeHelpers; 422 | 423 | DateTime input; 424 | bool output; 425 | 426 | input = new DateTime(1994, 12, 21, 22, 13, 08); 427 | 428 | output = input.IsThursday(); //output = false 429 | 430 | input = new DateTime(2019, 7, 18, 20, 13, 08); 431 | 432 | output = input.IsThursday(); //output = true 433 | 434 | input = new DateTime(2019, 7, 25); 435 | 436 | output = input.IsThursday(); //output = true 437 | ``` 438 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 439 | 440 | ### IsFriday 441 | ```C# 442 | //using Aqua.DateTimeHelpers; 443 | 444 | DateTime input; 445 | bool output; 446 | 447 | input = new DateTime(1994, 12, 22, 22, 13, 08); 448 | 449 | output = input.IsFriday(); //output = false 450 | 451 | input = new DateTime(2019, 7, 19, 20, 13, 08); 452 | 453 | output = input.IsFriday(); //output = true 454 | 455 | input = new DateTime(2019, 7, 26); 456 | 457 | output = input.IsFriday(); //output = true 458 | ``` 459 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 460 | 461 | ### IsSaturday 462 | ```C# 463 | //using Aqua.DateTimeHelpers; 464 | 465 | DateTime input; 466 | bool output; 467 | 468 | input = new DateTime(1994, 12, 23, 22, 13, 08); 469 | 470 | output = input.IsSaturday(); //output = false 471 | 472 | input = new DateTime(2019, 7, 20, 20, 13, 08); 473 | 474 | output = input.IsSaturday(); //output = true 475 | 476 | input = new DateTime(2019, 7, 27); 477 | 478 | output = input.IsSaturday(); //output = true 479 | ``` 480 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 481 | 482 | ### IsDateAM 483 | ```C# 484 | //using Aqua.DateTimeHelpers; 485 | 486 | DateTime input; 487 | bool output; 488 | 489 | input = new DateTime(1994, 12, 23, 22, 13, 08); 490 | 491 | output = input.IsDateAM(); //output = false 492 | 493 | input = new DateTime(2019, 7, 20, 03, 13, 08); 494 | 495 | output = input.IsDateAM(); //output = true 496 | 497 | input = new DateTime(2019, 7, 27); 498 | 499 | output = input.IsDateAM(); //output = true 500 | ``` 501 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 502 | 503 | ### IsDatePM 504 | ```C# 505 | //using Aqua.DateTimeHelpers; 506 | 507 | DateTime input; 508 | bool output; 509 | 510 | input = new DateTime(1994, 12, 23, 22, 13, 08); 511 | 512 | output = input.IsDatePM(); //output = true 513 | 514 | input = new DateTime(2019, 7, 20, 03, 13, 08); 515 | 516 | output = input.IsDatePM(); //output = false 517 | 518 | input = new DateTime(2019, 7, 27); 519 | 520 | output = input.IsDatePM(); //output = false 521 | ``` 522 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 523 | 524 | ### GenerateDateList 525 | ```C# 526 | //using Aqua.DateTimeHelpers; 527 | 528 | DateTime startDate; 529 | DateTime endDate; 530 | List output = new List(); 531 | 532 | startDate = new DateTime(1994, 12, 23); 533 | endDate = new DateTime(1994, 12, 29); 534 | 535 | output = DateTimeHelpers.GenerateDateList(startDate, endDate); 536 | //output = {"23/12/1994 00:00:00", "24/12/1994 00:00:00", "25/12/1994 00:00:00", "26/12/1994 00:00:00", 537 | // "27/12/1994 00:00:00", "28/12/1994 00:00:00", "29/12/1994 00:00:00", } 538 | 539 | ``` 540 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 541 | 542 | ### GenerateBusinessDaysList 543 | ```C# 544 | //using Aqua.DateTimeHelpers; 545 | 546 | DateTime startDate; 547 | DateTime endDate; 548 | List holydays = new List { 549 | new DateTime(2019, 1, 1 ), 550 | new DateTime(2019, 4, 19), 551 | new DateTime(2019, 4, 22), 552 | new DateTime(2019, 5, 6 ), 553 | new DateTime(2019, 5, 27), 554 | new DateTime(2019, 8, 26), 555 | new DateTime(2019, 12, 25), 556 | new DateTime(2019, 12, 26) 557 | }; 558 | 559 | List weekendDays = new List { 6, 0 }; 560 | 561 | IEnumerable output = new List(); 562 | 563 | startDate = new DateTime(2019, 1, 1); 564 | endDate = new DateTime(2019, 1, 9); 565 | 566 | output = DateTimeHelpers.GenerateBusinessDaysList(startDate, endDate, holydays, weekendDays); 567 | //output = {"02/01/2019 00:00:00", "03/01/2019 00:00:00", "04/01/2019 00:00:00", 568 | // "07/01/2019 00:00:00", "08/01/2019 00:00:00", "09/01/2019 00:00:00"} 569 | 570 | ``` 571 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 572 | 573 | ### GetLastWeekdayOfMonth 574 | ```C# 575 | //using Aqua.DateTimeHelpers; 576 | 577 | int year; 578 | int month; 579 | DayOfWeek dayOfWeek; 580 | 581 | DateTime output; 582 | 583 | year = 2019; 584 | month = 8; 585 | dayOfWeek = DayOfWeek.Sunday; 586 | output = DateTimeHelpers.GetLastWeekdayOfMonth(year, month, dayOfWeek); // "25/08/2019 00:00:00" 587 | 588 | year = 2019; 589 | month = 8; 590 | dayOfWeek = DayOfWeek.Friday; 591 | output = DateTimeHelpers.GetLastWeekdayOfMonth(year, month, dayOfWeek); // "30/08/2019 00:00:00" 592 | ``` 593 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 594 | 595 | ### GetFirstWeekdayOfMonth 596 | ```C# 597 | //using Aqua.DateTimeHelpers; 598 | 599 | int year; 600 | int month; 601 | DayOfWeek dayOfWeek; 602 | 603 | DateTime output; 604 | 605 | year = 2019; 606 | month = 8; 607 | dayOfWeek = DayOfWeek.Sunday; 608 | output = DateTimeHelpers.GetFirstWeekdayOfMonth(year, month, dayOfWeek); // "04/08/2019 00:00:00" 609 | 610 | year = 2019; 611 | month = 8; 612 | dayOfWeek = DayOfWeek.Friday; 613 | output = DateTimeHelpers.GetFirstWeekdayOfMonth(year, month, dayOfWeek); // "02/08/2019 00:00:00" 614 | ``` 615 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 616 | 617 | ### GetFirstDayOfWeek 618 | ```C# 619 | //using Aqua.DateTimeHelpers; 620 | 621 | DateTime input; 622 | DateTime output; 623 | 624 | input = new DateTime(2019, 5, 5); 625 | 626 | output = DateTimeHelpers.GetFirstDayOfWeek(input); // "29/04/2019 00:00:00" 627 | 628 | input = new DateTime(2019, 5, 15); 629 | 630 | output = DateTimeHelpers.GetFirstDayOfWeek(input); // "13/05/2019 00:00:00" 631 | ``` 632 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 633 | 634 | ### GetLastDayOfWeek 635 | ```C# 636 | //using Aqua.DateTimeHelpers; 637 | 638 | DateTime input; 639 | DateTime output; 640 | 641 | input = new DateTime(2019, 5, 5); 642 | 643 | output = DateTimeHelpers.GetLastDayOfWeek(input); // "05/05/2019 00:00:00" 644 | 645 | input = new DateTime(2019, 5, 15); 646 | 647 | output = DateTimeHelpers.GetLastDayOfWeek(input); // "19/05/2019 00:00:00" 648 | ``` 649 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 650 | 651 | ### GetLastDayOfPreviousWeek 652 | ```C# 653 | //using Aqua.DateTimeHelpers; 654 | 655 | DateTime input; 656 | DateTime output; 657 | 658 | input = new DateTime(2019, 5, 5); 659 | 660 | output = DateTimeHelpers.GetLastDayOfPreviousWeek(input); // "28/04/2019 00:00:00" 661 | 662 | input = new DateTime(2019, 5, 15); 663 | 664 | output = DateTimeHelpers.GetLastDayOfPreviousWeek(input); // "12/05/2019 00:00:00" 665 | ``` 666 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 667 | 668 | ### GetFirstDayOfNextWeek 669 | ```C# 670 | //using Aqua.DateTimeHelpers; 671 | 672 | DateTime input; 673 | DateTime output; 674 | 675 | input = new DateTime(2019, 5, 5); 676 | 677 | output = DateTimeHelpers.GetFirstDayOfNextWeek(input); // "06/05/2019 00:00:00" 678 | 679 | input = new DateTime(2019, 5, 15); 680 | 681 | output = DateTimeHelpers.GetFirstDayOfNextWeek(input); // "20/05/2019 00:00:00" 682 | ``` 683 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 684 | 685 | ### NextWeekSameDay 686 | ```C# 687 | //using Aqua.DateTimeHelpers; 688 | 689 | DateTime input; 690 | DateTime output; 691 | 692 | input = new DateTime(2019, 5, 5); 693 | 694 | output = input.NextWeekSameDay(); // "12/05/2019 00:00:00" 695 | 696 | input = new DateTime(2019, 5, 15); 697 | 698 | output = input.NextWeekSameDay(); // "22/05/2019 00:00:00" 699 | ``` 700 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 701 | 702 | ### PreviousWeekSameDay 703 | ```C# 704 | //using Aqua.DateTimeHelpers; 705 | 706 | DateTime input; 707 | DateTime output; 708 | 709 | input = new DateTime(2019, 5, 5); 710 | 711 | output = input.PreviousWeekSameDay(); // "28/04/2019 00:00:00" 712 | 713 | input = new DateTime(2019, 5, 15); 714 | 715 | output = input.PreviousWeekSameDay(); // "08/05/2019 00:00:00" 716 | ``` 717 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 718 | 719 | ### NextMonthSameDay 720 | ```C# 721 | //using Aqua.DateTimeHelpers; 722 | 723 | DateTime input; 724 | DateTime output; 725 | 726 | input = new DateTime(2019, 5, 5); 727 | 728 | output = input.NextMonthSameDay(); // "05/06/2019 00:00:00" 729 | 730 | input = new DateTime(2019, 5, 15); 731 | 732 | output = input.NextMonthSameDay(); // "15/06/2019 00:00:00" 733 | ``` 734 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 735 | 736 | ### PreviousMonthSameDay 737 | ```C# 738 | //using Aqua.DateTimeHelpers; 739 | 740 | DateTime input; 741 | DateTime output; 742 | 743 | input = new DateTime(2019, 5, 5); 744 | 745 | output = input.PreviousMonthSameDay(); // "05/04/2019 00:00:00" 746 | 747 | input = new DateTime(2019, 5, 15); 748 | 749 | output = input.PreviousMonthSameDay(); // "15/04/2019 00:00:00" 750 | ``` 751 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 752 | 753 | ### QuarterOfYear 754 | ```C# 755 | //using Aqua.DateTimeHelpers; 756 | 757 | DateTime input; 758 | int output; 759 | 760 | input = new DateTime(2019, 5, 5); 761 | 762 | output = input.QuarterOfYear(); // output = 2 763 | 764 | input = new DateTime(2019, 12, 15); 765 | 766 | output = input.QuarterOfYear(); // output = 24 767 | ``` 768 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 769 | 770 | ### WeekOfYear 771 | ```C# 772 | //using Aqua.DateTimeHelpers; 773 | 774 | DateTime input; 775 | int output; 776 | 777 | input = new DateTime(2019, 5, 5); 778 | 779 | output = input.WeekOfYear(); // output = 18 780 | 781 | input = new DateTime(2019, 12, 15); 782 | 783 | output = input.WeekOfYear(); // output = 50 784 | ``` 785 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 786 | 787 | ### Midnight 788 | ```C# 789 | //using Aqua.DateTimeHelpers; 790 | 791 | DateTime input; 792 | DateTime output; 793 | 794 | input = new DateTime(2019, 5, 5, 10, 10, 35); 795 | 796 | output = input.Midnight(); // output = "05/05/2019 00:00:00" 797 | 798 | input = new DateTime(2019, 12, 15, 13, 7, 55); 799 | 800 | output = input.Midnight(); // output = "15/12/2019 00:00:00" 801 | ``` 802 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 803 | 804 | ### Noon 805 | ```C# 806 | //using Aqua.DateTimeHelpers; 807 | 808 | DateTime input; 809 | DateTime output; 810 | 811 | input = new DateTime(2019, 5, 5, 10, 10, 35); 812 | 813 | output = input.Noon(); // output = "05/05/2019 12:00:00" 814 | 815 | input = new DateTime(2019, 12, 15, 13, 7, 55); 816 | 817 | output = input.Noon(); // output = "15/12/2019 12:00:00" 818 | ``` 819 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 820 | 821 | ### NextYearSameDay 822 | ```C# 823 | //using Aqua.DateTimeHelpers; 824 | 825 | DateTime input; 826 | DateTime output; 827 | 828 | input = new DateTime(2019, 5, 5, 10, 10, 35); 829 | 830 | output = input.NextYearSameDay(); // output = "05/05/2020 10:10:35" 831 | 832 | input = new DateTime(2019, 12, 15, 13, 7, 55); 833 | 834 | output = input.NextYearSameDay(); // output = "15/12/2020 13:07:55" 835 | ``` 836 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 837 | 838 | ### PreviousYearSameDay 839 | ```C# 840 | //using Aqua.DateTimeHelpers; 841 | 842 | DateTime input; 843 | DateTime output; 844 | 845 | input = new DateTime(2019, 5, 5, 10, 10, 35); 846 | 847 | output = input.PreviousYearSameDay(); // output = "05/05/2018 10:10:35" 848 | 849 | input = new DateTime(2019, 12, 15, 13, 7, 55); 850 | 851 | output = input.PreviousYearSameDay(); // output = "15/12/2018 13:07:55" 852 | ``` 853 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 854 | 855 | ### AgeCalenderYears 856 | ```C# 857 | //using Aqua.DateTimeHelpers; 858 | 859 | DateTime referenceDay; 860 | DateTime today; 861 | int output; 862 | 863 | referenceDay = new DateTime(1970, 5, 5, 10, 10, 35); 864 | today = new DateTime(2019, 11, 11); 865 | 866 | output = DateTimeHelpers.AgeCalenderYears(referenceDay, today); // output = 49 867 | 868 | referenceDay = new DateTime(1975, 12, 5, 10, 10, 35); 869 | today = new DateTime(2019, 11, 11); 870 | 871 | output = DateTimeHelpers.AgeCalenderYears(referenceDay, today); // output = 44 872 | ``` 873 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 874 | 875 | ### AgeMonths 876 | ```C# 877 | //using Aqua.DateTimeHelpers; 878 | 879 | DateTime referenceDay; 880 | DateTime today; 881 | int output; 882 | 883 | referenceDay = new DateTime(1970, 5, 5, 10, 10, 35); 884 | today = new DateTime(2019, 11, 11); 885 | 886 | output = DateTimeHelpers.AgeMonths(referenceDay, today); // output = 594 887 | 888 | referenceDay = new DateTime(1975, 12, 5, 10, 10, 35); 889 | today = new DateTime(2019, 11, 11); 890 | 891 | output = DateTimeHelpers.AgeMonths(referenceDay, today); // output = 527 892 | ``` 893 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 894 | 895 | ### AgeExactYears 896 | ```C# 897 | //using Aqua.DateTimeHelpers; 898 | 899 | DateTime referenceDay; 900 | DateTime today; 901 | decimal output; 902 | 903 | referenceDay = new DateTime(1970, 5, 5, 10, 10, 35); 904 | today = new DateTime(2019, 11, 11); 905 | 906 | output = DateTimeHelpers.AgeExactYears(referenceDay, today); // output = 49.5 907 | 908 | referenceDay = new DateTime(1975, 12, 5, 10, 10, 35); 909 | today = new DateTime(2019, 11, 11); 910 | 911 | output = DateTimeHelpers.AgeExactYears(referenceDay, today); // output = 43.92 912 | ``` 913 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 914 | 915 | ### SetTime 916 | ```C# 917 | //using Aqua.DateTimeHelpers; 918 | 919 | DateTime referenceDay; 920 | int inputHour; 921 | int inputMinute; 922 | int inputSecond; 923 | DateTime output; 924 | 925 | referenceDay = new DateTime(1970, 5, 5, 10, 10, 35); 926 | inputHour = 5; 927 | inputMinute = 5; 928 | inputSecond = 45; 929 | 930 | output = DateTimeHelpers.SetTime(referenceDay, inputHour, inputMinute, inputSecond); // "05/05/1970 05:05:45" 931 | 932 | referenceDay = new DateTime(1975, 12, 5, 10, 10, 35); 933 | inputHour = 15; 934 | inputMinute = 5; 935 | inputSecond = 45; 936 | 937 | output = DateTimeHelpers.SetTime(referenceDay, inputHour, inputMinute, inputSecond); // "15/05/1975 10:10:35" 938 | ``` 939 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 940 | 941 | ### SetDay 942 | ```C# 943 | //using Aqua.DateTimeHelpers; 944 | 945 | DateTime referenceDay; 946 | int day; 947 | DateTime output; 948 | 949 | referenceDay = new DateTime(1970, 5, 03, 05, 05, 45); 950 | day = 17; 951 | 952 | output = DateTimeHelpers.SetDay(referenceDay, day); // "17/05/1970 05:05:45" 953 | 954 | referenceDay = new DateTime(1975, 12, 5, 10, 10, 35); 955 | day = 22; 956 | 957 | output = DateTimeHelpers.SetDay(referenceDay, day); // "22/12/1975 10:10:35" 958 | ``` 959 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 960 | 961 | ### SetMonth 962 | ```C# 963 | //using Aqua.DateTimeHelpers; 964 | 965 | DateTime referenceDay; 966 | int month; 967 | DateTime output; 968 | 969 | referenceDay = new DateTime(1970, 5, 17, 05, 05, 45); 970 | month = 3; 971 | 972 | output = DateTimeHelpers.SetMonth(referenceDay, month); // "17/03/1970 05:05:45" 973 | 974 | referenceDay = new DateTime(1975, 12, 22, 10, 10, 35); 975 | month = 10; 976 | 977 | output = DateTimeHelpers.SetMonth(referenceDay, month); // "22/10/1975 10:10:35" 978 | ``` 979 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 980 | 981 | ### SetYear 982 | ```C# 983 | //using Aqua.DateTimeHelpers; 984 | 985 | DateTime referenceDay; 986 | int year; 987 | DateTime output; 988 | 989 | referenceDay = new DateTime(1970, 3, 17, 05, 05, 45); 990 | year = 1980; 991 | 992 | output = DateTimeHelpers.SetYear(referenceDay, year); // "17/03/1980 05:05:45" 993 | 994 | referenceDay = new DateTime(1975, 10, 22, 10, 10, 35); 995 | year = 2019; 996 | 997 | output = DateTimeHelpers.SetYear(referenceDay, year); // "22/10/2019 10:10:35" 998 | ``` 999 | :back:[Back to the Full List of Features](#List-Of-Features-and-Methods) 1000 | 1001 | # Build and Test 1002 | TODO: Describe and show how to build your code and run the tests. 1003 | 1004 | # Contribute 1005 | TODO: Explain how other users and developers can contribute to make your code better. 1006 | 1007 | If you want to learn more about creating good readme files then refer the following [guidelines](https://docs.microsoft.com/en-us/azure/devops/repos/git/create-a-readme?view=azure-devops). You can also seek inspiration from the below readme files: 1008 | - [ASP.NET Core](https://github.com/aspnet/Home) 1009 | - [Visual Studio Code](https://github.com/Microsoft/vscode) 1010 | - [Chakra Core](https://github.com/Microsoft/ChakraCore) 1011 | --------------------------------------------------------------------------------