GithubHelp home page GithubHelp logo

dahall / timespan2 Goto Github PK

View Code? Open in Web Editor NEW
22.0 6.0 9.0 195 KB

Library extending the .NET TimeSpan structure to be comparable, serializable, and convertible, and to support localized string formatting and parsing.

License: MIT License

C# 100.00%
timespan nuget dotnet csharp

timespan2's Introduction

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:

  • TimeSpan2 is a wrapper around the existing TimeSpan structure that adds serialization, comparability, and convertibility. It can be used anywhere a TimeSpan is used.
  • TimeSpanFormatInfo is an IFormatProvider for 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 for TimeSpanFormatInfo.
  • TimeSpanPicker is a editable ComboBox that exposes a localized list of TimeSpan instances and allows for text entry. This is only available in the TimeSpan2 package.

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:

Documentation

For sample code, see the Documentation.

Release History

  • 2.4.1 - Split into two packages (TimeSpan2.Core and TimeSpan2) 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

  1. Fork it (https://github.com/yourname/yourproject/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

timespan2's People

Contributors

dahall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

timespan2's Issues

How to show time in this format?

Hello:
I want to do some testing with your repo.
I created a WinForms project app with Visual Studio 2022, target .NET 6.0.
I installed NUGET package:
PM> Install-Package TimeSpan2 -Version 2.4.2
I added one TimeSpanPicker control to Form1 in Form Designer.

The following is my C# code:

namespace TimeSpan2Form
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private async void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i <= 10; i++)
            {
                await Task.Delay(1000);
                TimeSpan time1 = TimeSpan.FromSeconds(i);
                timeSpanPicker1.Value = time1;
            }
        }
    }
}

I can see the output like: 1 second; 2 seconds; 3 seconds; ... 10 seconds.
But how I can show the output like: 00:00:01; 00:00:02; 00:00:03; ... 00:00:10
Let me know how I can do this with C#?
Thanks,

I can

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.