AaTurpin.Utilities
A comprehensive .NET utility library providing robust helper methods for common DateTime and file path operations.
Installation
Install the package via NuGet Package Manager:
Install-Package AaTurpin.Utilities
Or via the .NET CLI:
dotnet add package AaTurpin.Utilities
Features
DateTimeUtils
Static utility class for common DateTime operations with ISO 8601 compliance:
- Get first day of week (using ISO 8601 standard where Monday is the first day)
- Get last day of week (using ISO 8601 standard where Sunday is the last day)
- Get ISO 8601 week number for a given date
- Get first and last day of month
PathUtils
Comprehensive static utility class for file path operations and manipulations:
- Path normalization for consistent comparison
- Drive letter normalization
- UNC path handling
- Path safety conversion for saving paths as filenames
- Relative path calculation
- Directory existence checks with auto-creation
- Safe path combination logic
Usage Examples
DateTimeUtils
using AaTurpin.Utilities;
using System;
DateTime monday = DateTimeUtils.GetFirstDayOfWeek(DateTime.Today);
DateTime sunday = DateTimeUtils.GetLastDayOfWeek(DateTime.Today);
int weekNumber = DateTimeUtils.GetIso8601WeekOfYear(DateTime.Today);
DateTime firstDayOfMonth = DateTimeUtils.GetFirstDayOfMonth(DateTime.Today);
DateTime lastDayOfMonth = DateTimeUtils.GetLastDayOfMonth(DateTime.Today);
PathUtils
using AaTurpin.Utilities;
using System;
string normalizedPath = PathUtils.NormalizePath(@"C:\Users\Username\Documents\");
string serverName = PathUtils.ExtractServerFromUncPath(@"\\Server01\Share\Folder");
string safePath = PathUtils.ConvertToFileSystemSafePath(@"C:\Project Files\Document.docx");
string originalPath = PathUtils.RestoreFromFileSystemSafePath(@"C\Project Files\Document.docx");
string relativePath = PathUtils.GetRelativePath(@"C:\Projects\MyProject\src\file.cs", @"C:\Projects\MyProject");
bool dirExists = PathUtils.EnsureDirectoryExists(@"C:\Temp\NewFolder");
bool parentDirExists = PathUtils.EnsureDirectoryExistsForFile(@"C:\Temp\NewFolder\file.txt");
string combinedPath = PathUtils.CombinePath("C:", "Users", "Username", "Documents");
Requirements
- .NET Framework 4.7.2 or higher
- Compatible with .NET Standard 2.0+ projects
License
MIT License