Skip to content

brokenegg-io/Brokenegg.MetaDate

Repository files navigation

Brokenegg.MetaDate

GitHub License Version Actions Actions GitHub branch checks state GitHub code size in bytes NuGet Downloads GitHub Contributors

Standarize the date across all your projects using this library. Library created for applications who needs to have a precise date and time on different timezones and locations.

Quick links

Installation

Our profile on the NuGet library brokenegg.io

Use the package manager NuGet to install DotIni.

nuget install brokenegg.metadate

Usage

using System.IO;
using Brokenegg.MetaDate;

Setting up global Locale

Setting global Time Zone as Manaus Time Zone (UTC-4)

USettings.Locale = ULocale.FindLocale(ELocales.MANAUS);

Converting date local to UTC (back and forth)

var date = DateTime.ParseExact("25/10/2021 20:25", "dd/MM/yyyy HH:mm", null);

var uDate = new UDate(date);
            
var local =  uDate.ToLocalDateTime();
var utc = uDate.ToUtcDateTime();

local should be the date 25/10/2021 20:25

utc should be the date 26/10/2021 00:25

Using setting on each case basis

You can use different locales for each date you want, instead of using a global setting, as shown bellow:

var date = DateTime.ParseExact("25/10/2021 20:25", "dd/MM/yyyy HH:mm", null);

var uDate = new UDate(date, ELocales.MANAUS);
            
var local =  uDate.ToLocalDateTime();
var utc = uDate.ToUtcDateTime();

local should be the date 25/10/2021 20:25

utc should be the date 26/10/2021 00:25

We have prepared the repo Brokenegg.MetaDate.Example which contains some usefull examples.

Contributing

If you didn't find your timezone listed on the xml file at Brokenegg.MetaDate.timezones.xml please open an issue or set up a pull request to the main branch and we will gladly integrate it. Remember to use _ to separate each word if your timezone has more than one word. Example of how the timezones is structured:

<locales>
    <locale>
        <name>MANAUS</name>
        <hours>-4</hours>
        <minutes>0</minutes>
    </locale>
<locales>    

And add the enum for your Timezone on the enum Brokenegg.MetaDate.ELocales :

public enum ELocales
{
   MANAUS,
}

Please make sure to update tests as appropriate.

get@brokenegg.io

License

MIT

About

Standarize the date across all your projects using this library. Library created for applications who needs to have a precise date and time on different timezones and locations.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages