Skip to content

Commit ba00f73

Browse files
feat: add TimecopContext and PointInTime. (#1)
1 parent 363d1be commit ba00f73

14 files changed

Lines changed: 364 additions & 3 deletions

.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# directories
2+
**/bin/
3+
**/obj/
4+
**/out/
5+
6+
# files
7+
Dockerfile*
8+
**/*.md
9+
10+
!README.md

.github/workflows/build.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
pull_request:
6+
branches:
7+
- main
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 15
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
- name: Build
16+
run: docker build --target build .
17+
- name: Test
18+
run: docker build --target test .

.github/workflows/publish.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
on:
2+
release:
3+
types: [released]
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
timeout-minutes: 15
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v3
11+
- name: Set VERSION variable from tag
12+
run: echo "VERSION=${GITHUB_REF/refs\/tags\/}" >> $GITHUB_ENV
13+
- name: Build
14+
run: docker build --target build .
15+
- name: Test
16+
run: docker build --target test .
17+
- name: Pack & Publish
18+
run: docker build --target pack-and-push --build-arg PackageVersion=${VERSION} --build-arg NuGetApiKey=${{secrets.NUGET_API_KEY}} .
19+

Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
2+
WORKDIR /source
3+
4+
# copy csproj and restore as distinct layers
5+
COPY *.sln .
6+
COPY src/Timecop.Core/Timecop.Core.csproj ./src/Timecop.Core/Timecop.Core.csproj
7+
COPY test/Timecop.Core.Tests/Timecop.Core.Tests.csproj ./test/Timecop.Core.Tests/Timecop.Core.Tests.csproj
8+
RUN dotnet restore
9+
10+
# copy everything else and build app
11+
COPY ./ ./
12+
WORKDIR /source
13+
RUN dotnet build -c release -o /out/package --no-restore
14+
15+
FROM build as test
16+
ENV TZ="Africa/Johannesburg"
17+
18+
RUN dotnet test
19+
20+
FROM build as pack-and-push
21+
WORKDIR /source
22+
23+
ARG PackageVersion
24+
ARG NuGetApiKey
25+
26+
RUN dotnet pack ./src/Timecop.Core/Timecop.Core.csproj -o /out/package -c Release
27+
RUN dotnet nuget push /out/package/Timecop.Core.$PackageVersion.nupkg -k $NuGetApiKey -s https://api.nuget.org/v3/index.json

LICENSE renamed to LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 timecop-net
3+
Copyright (c) 2023 Timecop.Core
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# Timecop.Core
2-
Core components that power Timecop
1+
# Core components that power Timecop
2+
3+
This package contains components used by Timecop. You do not need to install it explicitly.

Timecop.Core.sln

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.6.33801.468
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Timecop.Core", "src\Timecop.Core\Timecop.Core.csproj", "{2C81D165-C2C1-40DF-9D9E-0E21FE5DA730}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Timecop.Core.Tests", "test\Timecop.Core.Tests\Timecop.Core.Tests.csproj", "{F7EDE0C3-FB11-44D2-8A1C-5600EFFE9350}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C1BA49EC-D151-491B-B78F-7B1A2A06212E}"
11+
ProjectSection(SolutionItems) = preProject
12+
Dockerfile = Dockerfile
13+
README.md = README.md
14+
EndProjectSection
15+
EndProject
16+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{92009F6C-93D2-4099-9671-34CC6D362E6C}"
17+
ProjectSection(SolutionItems) = preProject
18+
.github\workflows\build.yml = .github\workflows\build.yml
19+
.github\workflows\publish.yml = .github\workflows\publish.yml
20+
EndProjectSection
21+
EndProject
22+
Global
23+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
24+
Debug|Any CPU = Debug|Any CPU
25+
Release|Any CPU = Release|Any CPU
26+
EndGlobalSection
27+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
28+
{2C81D165-C2C1-40DF-9D9E-0E21FE5DA730}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{2C81D165-C2C1-40DF-9D9E-0E21FE5DA730}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{2C81D165-C2C1-40DF-9D9E-0E21FE5DA730}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{2C81D165-C2C1-40DF-9D9E-0E21FE5DA730}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{F7EDE0C3-FB11-44D2-8A1C-5600EFFE9350}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{F7EDE0C3-FB11-44D2-8A1C-5600EFFE9350}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{F7EDE0C3-FB11-44D2-8A1C-5600EFFE9350}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{F7EDE0C3-FB11-44D2-8A1C-5600EFFE9350}.Release|Any CPU.Build.0 = Release|Any CPU
36+
EndGlobalSection
37+
GlobalSection(SolutionProperties) = preSolution
38+
HideSolutionNode = FALSE
39+
EndGlobalSection
40+
GlobalSection(NestedProjects) = preSolution
41+
{92009F6C-93D2-4099-9671-34CC6D362E6C} = {C1BA49EC-D151-491B-B78F-7B1A2A06212E}
42+
EndGlobalSection
43+
GlobalSection(ExtensibilityGlobals) = postSolution
44+
SolutionGuid = {253AFEBF-AC05-42DD-A938-CE1B03291A8D}
45+
EndGlobalSection
46+
EndGlobal

Timecop.Core.sln.DotSettings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Timecop/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

src/Timecop.Core/PointInTime.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
3+
namespace TCop.Core;
4+
5+
public readonly struct PointInTime
6+
{
7+
private static readonly long BclEpochRelativeToUnixEpochTicks = -(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks);
8+
9+
public long UnixEpochTicks { get; }
10+
11+
public DateTime DateTime => new(UnixEpochTicks - BclEpochRelativeToUnixEpochTicks, DateTimeKind.Utc);
12+
13+
public static PointInTime Now => new(DateTime.UtcNow);
14+
15+
public PointInTime(long unixEpochTicks)
16+
{
17+
UnixEpochTicks = unixEpochTicks;
18+
}
19+
20+
public PointInTime(DateTime dateTime)
21+
{
22+
UnixEpochTicks = dateTime.Ticks + BclEpochRelativeToUnixEpochTicks;
23+
}
24+
25+
public PointInTime Plus(TimeSpan span)
26+
{
27+
return new PointInTime(UnixEpochTicks + span.Ticks);
28+
}
29+
30+
public PointInTime Minus(TimeSpan span)
31+
{
32+
return new PointInTime(UnixEpochTicks - span.Ticks);
33+
}
34+
35+
public TimeSpan Minus(PointInTime pointInTime)
36+
{
37+
return TimeSpan.FromTicks(UnixEpochTicks - pointInTime.UnixEpochTicks);
38+
}
39+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<PackageId>Timecop.Core</PackageId>
5+
<Description>Components that power Timecop.</Description>
6+
<Authors>Dmytro Khmara</Authors>
7+
<Copyright>Copyright Dmytro Khmara</Copyright>
8+
<PackageReadmeFile>README.md</PackageReadmeFile>
9+
<PackageTags>DateTime;Date;Time;Unit;Testing;</PackageTags>
10+
<!--PackageIcon>icon.png</PackageIcon>-->
11+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
12+
<RepositoryType>git</RepositoryType>
13+
<RepositoryUrl>https://github.com/timecop-net/Timecop.Core</RepositoryUrl>
14+
15+
<TargetFramework>netstandard2.0</TargetFramework>
16+
<Nullable>enable</Nullable>
17+
<LangVersion>10.0</LangVersion>
18+
</PropertyGroup>
19+
20+
<Target Name="SetNuspecProperties" BeforeTargets="GenerateNuspec">
21+
<PropertyGroup>
22+
<NuspecProperties>$(NuspecProperties);config=$(Configuration)</NuspecProperties>
23+
<NuspecProperties>$(NuspecProperties);version=$(PackageVersion)</NuspecProperties>
24+
</PropertyGroup>
25+
<Message Importance="high" Text="NuspecProperties: $(NuspecProperties)" />
26+
</Target>
27+
28+
<ItemGroup>
29+
<None Include="..\..\README.md" Pack="true" PackagePath="" />
30+
<!--<None Include="..\..\icon.png" Pack="true" PackagePath="" />-->
31+
32+
<PackageReference Include="MinVer" Version="4.3.0">
33+
<PrivateAssets>all</PrivateAssets>
34+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
35+
</PackageReference>
36+
</ItemGroup>
37+
38+
</Project>

0 commit comments

Comments
 (0)