Skip to content

Instantly share code, notes, and snippets.

View rbeauchamp's full-sized avatar

Richard Beauchamp rbeauchamp

  • 100% Remote
  • 22:30 (UTC -07:00)
View GitHub Profile
@rbeauchamp
rbeauchamp / Iso8601DurationParser.cs
Created May 9, 2023 19:38
ISO 8601 Duration Parser and Test Class: A C# implementation of an ISO 8601 duration parser with comprehensive test coverage, including leap year scenarios and edge cases. Easily parse ISO 8601 duration strings into TimeSpan objects, and handle positive and negative durations.
using System.Text.RegularExpressions;
/// <summary>
/// Represents an ISO 8601 duration string parser. This parser converts ISO 8601 duration strings
/// into <see cref="TimeSpan" /> objects.
/// </summary>
/// <remarks>
/// <para>
/// The ISO 8601 duration format is a compact string representation of a duration, which can include
/// years, months, weeks, days, hours, minutes, and seconds.