TimeSpan2
Library extending the .NET TimeSpan structure to be comparable, serializable, and convertible, and to support localized string formatting and parsing.
Install / Use
/learn @dahall/TimeSpan2README
TimeSpan2
Library extending the .NET TimeSpan structure to be comparable, serializable, and convertible, and to support localized string formatting and parsing.
There are three public classes of note:
TimeSpan2is a wrapper around the existingTimeSpanstructure that adds serialization, comparability, and convertibility. It can be used anywhere a TimeSpan is used.TimeSpanFormatInfois anIFormatProviderfor TimeSpan instances and provides a richer set of output formats. It works similarly to DateTimeFormatInfo. If you use the TimeSpan2 structure, you can access the parsing and output functionality directly from the structure's Parse and ToString methods. A list of format strings can be found here and in the inline documentation forTimeSpanFormatInfo.TimeSpanPickeris a editable ComboBox that exposes a localized list of TimeSpan instances and allows for text entry. This is only available in theTimeSpan2package.
This project has translations for English, Spanish, French, Italian, Russian, Chinese, and German. If anyone would like to provide translations for other languages, or better ones for those in the project, please post them in the Discussions area.
Installation
This is a standard Visual Studio 2022 solution containing the core library and control library as projects and a test harness as another project.
It is available for inclusion into .NET projects via NuGet:
- TimeSpan2.Core - System neutral, localized time spans..
- TimeSpan2 - WinForms control for natural language time spans.
Documentation
For sample code, see the Documentation.
Release History
- 2.4.1 - Split into two packages (
TimeSpan2.CoreandTimeSpan2) to remove WinForms dependency from core package. - 2.4.0 - Added support for .NET 6.0
- 2.3.0 - Added support for .NET Core 3.0 and 3.1
- 2.1.6 - Added Dutch and fixed a bug
- 2.1.5 - Added Danish
- 2.1.4 - Added .NET version builds
- 2.1.1 - Minor bug fixes and new languages added
- Since 2.0.1 - Added .NET 2.0 and 4.0 assemblies and build, improved performance, added support for IXmlSerialization, improved error checking.
Not backwards compatible with 1.x library. Aligned and expanded upon functionality in .NET 4.0. Provides TimeSpan2FormatInfo which is culturally aware. It now provides an advanced syntax for formatting and parsing. TimeSpan2 is now functionally equivalent to the 4.0 TimeSpan. See inline Documentation for more detail on syntax. Significant work to enrich design-time experience with TimeSpanPicker.
Contributing
- Fork it (https://github.com/yourname/yourproject/fork)
- Create your feature branch (
git checkout -b feature/fooBar) - Commit your changes (
git commit -am 'Add some fooBar') - Push to the branch (
git push origin feature/fooBar) - Create a new Pull Request
Related Skills
openhue
344.4kControl Philips Hue lights and scenes via the OpenHue CLI.
sag
344.4kElevenLabs text-to-speech with mac-style say UX.
weather
344.4kGet current weather and forecasts via wttr.in or Open-Meteo
tweakcc
1.5kCustomize Claude Code's system prompts, create custom toolsets, input pattern highlighters, themes/thinking verbs/spinners, customize input box & user message styling, support AGENTS.md, unlock private/unreleased features, and much more. Supports both native/npm installs on all platforms.
