-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41353e2
commit 3f6436c
Showing
7 changed files
with
289 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
File renamed without changes