From 3f6436c2729e7b66b4d7f6a71b4d13bb1d5e414f Mon Sep 17 00:00:00 2001 From: Dejan FAJFAR Date: Sun, 12 Nov 2023 11:26:20 +0100 Subject: [PATCH] Build and publish --- .github/workflows/deploy.yml | 50 +++++++++ .github/workflows/dotnet.yml | 26 ++--- .github/workflows/master_pr.yml | 25 +++-- Epoch.net/CHANGELOG.md | 70 +++++++++++++ Epoch.net/Epoch.net.csproj | 12 ++- Epoch.net/README.md | 133 ++++++++++++++++++++++++ images/{logo_square_64.png => icon.png} | Bin 7 files changed, 289 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 Epoch.net/CHANGELOG.md create mode 100644 Epoch.net/README.md rename images/{logo_square_64.png => icon.png} (100%) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..7215994 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,50 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: Deploy + +on: + push: + tags: + - "*" # Only run if a tag is pressent + workflow_dispatch: + +jobs: + Build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: | + 7.0.x + 6.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --configuration Release --no-restore -warnaserror + - name: Test + run: dotnet test --verbosity normal + Deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Get Tag + id: tag + run: echo "::set-output name=tag::${{ github.ref }}" + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: | + 7.0.x + 6.0.x + - name: Restore dependencies + run: dotnet restore + - name: Pack + run: doitnet pack --output nupkgs -p:PackageVersion=${{ steps.tag.outputs.tag }} -p Configuration="Release" + - name: Publish Artifact + uses: actions/upload-artifact@v2 + with: + name: Package + path: nupkgs diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index eb2c6b8..c37ff51 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -5,24 +5,24 @@ name: BuildAndTest on: push: - branches: [ "*" ] + branches: ["*"] + tags: "!*" # Do not run if tags a re pressent jobs: build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: | + - uses: actions/checkout@v3 + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: | 7.0.x 6.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --no-restore - - name: Test - run: dotnet test --no-build --verbosity normal + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --no-restore + - name: Test + run: dotnet test --no-build --verbosity normal diff --git a/.github/workflows/master_pr.yml b/.github/workflows/master_pr.yml index 4329f2d..a0c6be2 100644 --- a/.github/workflows/master_pr.yml +++ b/.github/workflows/master_pr.yml @@ -5,24 +5,23 @@ name: master_pr on: pull_request: - branches: [ "master" ] + branches: ["master"] jobs: build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: | + - uses: actions/checkout@v3 + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: | 7.0.x 6.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --configuration Release --no-restore -warnaserror - - name: Test - run: dotnet test --verbosity normal + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --configuration Release --no-restore -warnaserror + - name: Test + run: dotnet test --verbosity normal diff --git a/Epoch.net/CHANGELOG.md b/Epoch.net/CHANGELOG.md new file mode 100644 index 0000000..adbd79d --- /dev/null +++ b/Epoch.net/CHANGELOG.md @@ -0,0 +1,70 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/) +and this project adheres to [Semantic Versioning](http://semver.org/). + +## ๐Ÿท๏ธ 4.0 + +### โ™ป๏ธ Changed + +- Updated to .net version 7 +- Moved build to github actions +- Updated code formatting to new standard + +### โœจ Added + +- DateOnly extensions +- TimeOnly extensions + +### ๐Ÿ”ฅ Removed + +- The Constants static class + +## ๐Ÿท๏ธ 3.1 + +### โœจ Added + +- LongEpochTime ToString method +- EpochTime ToString method + +## ๐Ÿท๏ธ 3.0 + +### โœจ Added + +- LongEpochTime +- EpochTime.ShortEpoch +- EpochTime.RawEpoch +- EpochTime.DateTime +- EpochTime.TimeSpan +- EpochTime.Add +- EpochValidator +- EpochTimeValueException +- ITimeProvider +- DefaultTimeProvider +- Long extensions methods + +### ๐Ÿ”ฅ Removed + +- EpochOverflowException +- EpochTime.AddSeconds +- EpochTime.ToRawEpoch +- EpochTime.ToDateTime +- EpochTime.ToTimeSpan + +## ๐Ÿท๏ธ 2.0 + +### โ™ป๏ธ Changed + +- Renamed the ```Epoch``` class to ```EpochTime``` to fix the name collision with the namespace. +- Updated the README.md to reflect the new naming + +### ๐Ÿ› Fixed + +- The name collision bug + +## ๐Ÿท๏ธ 1.1 + +### ๐Ÿ› Fixed + +* DateTime.ToRawEpoch now thrown an EpochOverflow exception if the resulting epoch is not storable in an integer diff --git a/Epoch.net/Epoch.net.csproj b/Epoch.net/Epoch.net.csproj index c07eb6c..756926b 100644 --- a/Epoch.net/Epoch.net.csproj +++ b/Epoch.net/Epoch.net.csproj @@ -15,10 +15,20 @@ - https://raw.githubusercontent.com/dejanfajfar/epoch.net/master/images/logo_square_64.png + icon.png posix unix timestamp epoch datetime timespan library core standard https://github.com/dejanfajfar/epoch.net + README.md + CHANGELOG.md + LICENSE True + + + + + + + diff --git a/Epoch.net/README.md b/Epoch.net/README.md new file mode 100644 index 0000000..4ee21a4 --- /dev/null +++ b/Epoch.net/README.md @@ -0,0 +1,133 @@ +![](https://raw.githubusercontent.com/dejanfajfar/epoch.net/master/images/logo.png) + +--- + +![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/dejanfajfar/epoch.net/dotnet.yml?style=flat-square) +![Nuget](https://img.shields.io/nuget/dt/epoch.net?style=flat-square&link=https%3A%2F%2Fwww.nuget.org%2Fpackages%2FEpoch.net) +![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/epoch.net?style=flat-square&link=https%3A%2F%2Fwww.nuget.org%2Fpackages%2FEpoch.net) + +--- + +# ๐Ÿ‘‹ Introduction + +> A simple and non-intrusive library for all your epoch needs + +```csharp +using Epoch.net; + +... +var timestamp = EpochTime.Now; +... + +``` + +## ๐Ÿค” What is an Epoch + +Epoch is shorthand for _Unix epoch time_ or as it is also known __POSIX time__. + +__Short version:__ The number of seconds since __1970-01-01T00:00:00Z__ without leap seconds. + +__Long version:__ [unix time](https://en.wikipedia.org/wiki/Unix_time) + +## Motivation + +With __.net core__ working on all major operating systems and most of them using POSIX to denote time and timestamps. +Not to mention the myriad of 3rd party tools, using POSIX time internally. The need for a working and tested implementation became clearer and clearer. +Additionally I did not want to write this logic in an inferior form in many of my applications. +So this little library was written. + +Its sole purpose is to make the work with these unix timestamps as easy as possible. + +For this purpose this library contains extension methods that build upon the existing __DateTime__, __TimeSpan__, __int__ and __long__ types. + +# ๐Ÿ“– Glossary + +| Term | Description | +|:-----|:-------------| +| EpochTime | Represents a POSIX time instance exact to the _second_ | +| EpochTimestamp | The number of seconds since 1970-01-01T00:00Z | +| LongEpochTime | Represents a POSIX time instance exact to the _millisecond_ | +| LongEpochTimestamp | The number of milliseconds since 1970-01-01T00:00Z | + +## Difference between `EpochTime` and `LongEpochTime` + +The initial difference was precision. _EpochTime_ will only be accurate to the nearest second on the other hand _LongEpochTime_ is accurate to the millisecond. +From this precision difference I decided to differentiate then by their __underlying__ base type. + +`EpochTime` is based on `int32` / `int` + +`LongEpochTime` is based on `int64` / `long` + +> โ—This is sadly implies that if you get a POSIX timestamp from somewhere you, the developer, have to know if it is representing milliseconds or seconds! + +## Ranges + +| Unit | Min value | Max value | +|:----|----:|----:| +| EpochTimestamp | -2147483648 | 2147483647 | +| LongEpochTimestamp | -922337203685477 | 922337203685477 | + +๐Ÿ“ _Note:_ The range of the `LongEpoch` is theoretically limited only by the range of `int64`. + +# โœ… Features + +- EpochTime a second precise POSIX time wrapper +- LongEpochTime a millisecond precise POSIX time wrapper +- Extension methods for build in time handling classes: + - DateTime + - TimeSpan + - DateOnly + - TimeOnly +- Fully tested ;) + +# ๐Ÿƒโ€โ™‚๏ธ Quick start + +## Add the package to yor project + +The preferred way of integrating the library is to use the [nuget package](https://www.nuget.org/packages/Epoch.net). This is easily done be either: + +```shell +dotnet add package Epoch.net +``` + +or + +```shell +Install-Package Epoch.net +``` + +## Reference + +After the package is added to the project add the using directive: + +```csharp +... +using Epoch.net; +... +``` + +Done ๐ŸŽ‰ + +# ๐Ÿฆฎ Helping out + +Everyone can help in their own way. + +Here are just some ideas: + +- Create a [ticket](https://github.com/dejanfajfar/epoch.net/issues) with a improvement suggestion +- Create a [ticket](https://github.com/dejanfajfar/epoch.net/issues) with a bug or issue you may be having +- Create a [ticket](https://github.com/dejanfajfar/epoch.net/issues) with a question that you may be having +- Have a look at the code and suggest improvements +- Spread the word of its existence +- And for the hardcore among you you can help me with the documentation ๐Ÿ˜ˆ + +# ๐Ÿ”— Links + +- [Changelog](https://github.com/dejanfajfar/epoch.net/blob/master/CHANGELOG.md) +- [Wiki](https://github.com/dejanfajfar/epoch.net/wiki) +- [Nuge](https://www.nuget.org/packages/Epoch.net) + +# โญ๏ธ Next steps + +- Consult the [Wiki](https://github.com/dejanfajfar/epoch.net/wiki) +- Create a [ticket](https://github.com/dejanfajfar/epoch.net/issues) to help the project improve \ No newline at end of file diff --git a/images/logo_square_64.png b/images/icon.png similarity index 100% rename from images/logo_square_64.png rename to images/icon.png