Git Product home page Git Product logo

brokenegg.metadate's Introduction

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.

[email protected]

License

MIT

brokenegg.metadate's People

Contributors

marcoaslima avatar

Stargazers

 avatar

Watchers

 avatar

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.