Skip to content

Commit c69ebee

Browse files
committed
initial commit
0 parents  commit c69ebee

11 files changed

Lines changed: 467 additions & 0 deletions

.gitignore

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.userosscache
8+
*.sln.docstates
9+
10+
# User-specific files (MonoDevelop/Xamarin Studio)
11+
*.userprefs
12+
13+
# Build results
14+
[Dd]ebug/
15+
[Dd]ebugPublic/
16+
[Rr]elease/
17+
[Rr]eleases/
18+
x64/
19+
x86/
20+
src/**/build/
21+
tests/**/build/
22+
bld/
23+
[Bb]in/
24+
[Oo]bj/
25+
26+
# Visual Studo 2015 cache/options directory
27+
.vs/
28+
29+
# MSTest test Results
30+
[Tt]est[Rr]esult*/
31+
[Bb]uild[Ll]og.*
32+
33+
# NUNIT
34+
*.VisualState.xml
35+
TestResult.xml
36+
37+
# Build Results of an ATL Project
38+
[Dd]ebugPS/
39+
[Rr]eleasePS/
40+
dlldata.c
41+
42+
# ASP.NET 5
43+
project.lock.json
44+
artifacts/
45+
46+
*_i.c
47+
*_p.c
48+
*_i.h
49+
*.ilk
50+
*.meta
51+
*.obj
52+
*.pch
53+
*.pdb
54+
*.pgc
55+
*.pgd
56+
*.rsp
57+
*.sbr
58+
*.tlb
59+
*.tli
60+
*.tlh
61+
*.tmp
62+
*.tmp_proj
63+
*.log
64+
*.vspscc
65+
*.vssscc
66+
.builds
67+
*.pidb
68+
*.svclog
69+
*.scc
70+
71+
# Chutzpah Test files
72+
_Chutzpah*
73+
74+
# Visual C++ cache files
75+
ipch/
76+
*.aps
77+
*.ncb
78+
*.opensdf
79+
*.sdf
80+
*.cachefile
81+
82+
# Visual Studio profiler
83+
*.psess
84+
*.vsp
85+
*.vspx
86+
87+
# TFS 2012 Local Workspace
88+
$tf/
89+
90+
# Guidance Automation Toolkit
91+
*.gpState
92+
93+
# ReSharper is a .NET coding add-in
94+
_ReSharper*/
95+
*.[Rr]e[Ss]harper
96+
*.DotSettings.user
97+
98+
# JustCode is a .NET coding addin-in
99+
.JustCode
100+
101+
# TeamCity is a build add-in
102+
_TeamCity*
103+
104+
# DotCover is a Code Coverage Tool
105+
*.dotCover
106+
107+
# NCrunch
108+
_NCrunch_*
109+
.*crunch*.local.xml
110+
111+
# MightyMoose
112+
*.mm.*
113+
AutoTest.Net/
114+
115+
# Web workbench (sass)
116+
.sass-cache/
117+
118+
# Installshield output folder
119+
[Ee]xpress/
120+
121+
# DocProject is a documentation generator add-in
122+
DocProject/buildhelp/
123+
DocProject/Help/*.HxT
124+
DocProject/Help/*.HxC
125+
DocProject/Help/*.hhc
126+
DocProject/Help/*.hhk
127+
DocProject/Help/*.hhp
128+
DocProject/Help/Html2
129+
DocProject/Help/html
130+
131+
# Click-Once directory
132+
publish/
133+
134+
# Publish Web Output
135+
*.[Pp]ublish.xml
136+
*.azurePubxml
137+
# TODO: Comment the next line if you want to checkin your web deploy settings
138+
# but database connection strings (with potential passwords) will be unencrypted
139+
*.pubxml
140+
*.publishproj
141+
142+
# NuGet Packages
143+
*.nupkg
144+
# The packages folder can be ignored because of Package Restore
145+
**/packages/*
146+
# except build/, which is used as an MSBuild target.
147+
!**/packages/build/
148+
# Uncomment if necessary however generally it will be regenerated when needed
149+
#!**/packages/repositories.config
150+
151+
# Windows Azure Build Output
152+
csx/
153+
*.build.csdef
154+
155+
# Windows Store app package directory
156+
AppPackages/
157+
158+
# Others
159+
*.[Cc]ache
160+
ClientBin/
161+
~$*
162+
*~
163+
*.dbmdl
164+
*.dbproj.schemaview
165+
*.pfx
166+
*.publishsettings
167+
node_modules/
168+
bower_components/
169+
170+
# RIA/Silverlight projects
171+
Generated_Code/
172+
173+
# Backup & report files from converting an old project file
174+
# to a newer Visual Studio version. Backup files are not needed,
175+
# because we have git ;-)
176+
_UpgradeReport_Files/
177+
Backup*/
178+
UpgradeLog*.XML
179+
UpgradeLog*.htm
180+
181+
# SQL Server files
182+
*.mdf
183+
*.ldf
184+
185+
# Business Intelligence projects
186+
*.rdl.data
187+
*.bim.layout
188+
*.bim_*.settings
189+
190+
# Microsoft Fakes
191+
FakesAssemblies/
192+
193+
# Node.js Tools for Visual Studio
194+
.ntvs_analysis.dat
195+
196+
# Visual Studio 6 build log
197+
*.plg
198+
199+
# Visual Studio 6 workspace options file
200+
*.opt
201+
202+
**/node_modules
203+
**/node_modules/*
204+
**/Images/ActualOutput
205+
**/Images/ReferenceOutput
206+
207+
# ASP.NET 5
208+
project.lock.json
209+
artifacts/
210+
211+
#BenchmarkDotNet
212+
**/BenchmarkDotNet.Artifacts/
213+
214+
# Build process
215+
*.csproj.bak
216+
217+
#CodeCoverage
218+
**/CodeCoverage/*
219+
docs/
220+
/samples/AvatarWithRoundedCorner/output
221+
/ImageSharp.Coverage.xml

Tocsoft.Clock.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27130.2020
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tocsoft.DateTimeAbstractions", "Tocsoft.Clock\Tocsoft.DateTimeAbstractions.csproj", "{48B75F8E-2EFC-4A36-8B4C-EB12EA1459E6}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tocsoft.DateTimeAbstractions.Tests", "Tocsoft.DateTimeAbstractions.Tests\Tocsoft.DateTimeAbstractions.Tests.csproj", "{F59B2FEE-7E98-4DE5-8BBA-3D628FB2F615}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{48B75F8E-2EFC-4A36-8B4C-EB12EA1459E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{48B75F8E-2EFC-4A36-8B4C-EB12EA1459E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{48B75F8E-2EFC-4A36-8B4C-EB12EA1459E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{48B75F8E-2EFC-4A36-8B4C-EB12EA1459E6}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{F59B2FEE-7E98-4DE5-8BBA-3D628FB2F615}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{F59B2FEE-7E98-4DE5-8BBA-3D628FB2F615}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{F59B2FEE-7E98-4DE5-8BBA-3D628FB2F615}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{F59B2FEE-7E98-4DE5-8BBA-3D628FB2F615}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {4FD45AB1-EAB7-4AC9-85D4-1E6463CC8D29}
30+
EndGlobalSection
31+
EndGlobal

Tocsoft.Clock/DateTime/Clock.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading;
4+
5+
namespace Tocsoft.DateTimeAbstractions
6+
{
7+
public static class Clock
8+
{
9+
private static AsyncLocal<Stack<DateTimeProvider>> clockStack = new AsyncLocal<Stack<DateTimeProvider>>();
10+
11+
public static DateTimeProvider DefaultProvider { get; set; } = new CurrentDateTimeProvider();
12+
13+
static Clock()
14+
{
15+
clockStack.Value = new Stack<DateTimeProvider>();
16+
}
17+
18+
private static DateTimeProvider Current
19+
{
20+
get
21+
{
22+
if (clockStack.Value.Count > 0)
23+
{
24+
return clockStack.Value.Peek();
25+
}
26+
else
27+
{
28+
return DefaultProvider;
29+
}
30+
}
31+
}
32+
33+
public static IDisposable Pin()
34+
{
35+
return Pin(new StaticDateTimeProvider(Now));
36+
}
37+
38+
internal static IDisposable Pin(DateTimeProvider provider)
39+
{
40+
clockStack.Value.Push(provider);
41+
return new PopWhenDisposed();
42+
}
43+
44+
private static void Pop()
45+
{
46+
clockStack.Value.Pop();
47+
}
48+
49+
private sealed class PopWhenDisposed : IDisposable
50+
{
51+
private bool disposed;
52+
53+
public void Dispose()
54+
{
55+
if (disposed)
56+
{
57+
return;
58+
}
59+
60+
Pop();
61+
disposed = true;
62+
}
63+
}
64+
65+
public static DateTime Now => Current.Now();
66+
}
67+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace Tocsoft.DateTimeAbstractions
4+
{
5+
public class CurrentDateTimeProvider : DateTimeProvider
6+
{
7+
public override DateTime Now()
8+
{
9+
return DateTime.UtcNow;
10+
}
11+
}
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace Tocsoft.DateTimeAbstractions
4+
{
5+
public abstract class DateTimeProvider
6+
{
7+
public abstract DateTime Now();
8+
}
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
3+
namespace Tocsoft.DateTimeAbstractions
4+
{
5+
public class StaticDateTimeProvider : DateTimeProvider
6+
{
7+
private readonly DateTime date;
8+
9+
public StaticDateTimeProvider(DateTime date)
10+
{
11+
this.date = date;
12+
}
13+
14+
public override DateTime Now()
15+
{
16+
return date;
17+
}
18+
}
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace Tocsoft.DateTimeAbstractions
4+
{
5+
public class UtcCurrentDateTimeProvider : DateTimeProvider
6+
{
7+
public override DateTime Now()
8+
{
9+
return DateTime.UtcNow;
10+
}
11+
}
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+

2+
using System.Runtime.CompilerServices;
3+
4+
5+
[assembly: InternalsVisibleTo("Tocsoft.DateTimeAbstractions.Tests")]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>

0 commit comments

Comments
 (0)