-
-
Notifications
You must be signed in to change notification settings - Fork 424
/
Copy pathTime.cs
52 lines (45 loc) · 1.25 KB
/
Time.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using LanguageExt.Traits;
using LanguageExt.Sys.Traits;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace LanguageExt.Sys;
/// <summary>
/// DateTime IO
/// </summary>
public static class Time<M, RT>
where M :
Monad<M>
where RT :
Has<M, TimeIO>
{
static readonly K<M, TimeIO> timeIO =
Has<M, RT, TimeIO>.ask;
/// <summary>
/// Current local date time
/// </summary>
public static K<M, DateTime> now =>
timeIO.Bind(e => e.Now);
/// <summary>
/// Current universal date time
/// </summary>
public static K<M, DateTime> nowUTC =>
timeIO.Bind(e => e.UtcNow);
/// <summary>
/// Today's date
/// </summary>
public static K<M, DateTime> today =>
timeIO.Bind(e => e.Today);
/// <summary>
/// Pause a task until a specified time
/// </summary>
[Pure, MethodImpl(EffOpt.mops)]
public static K<M, Unit> sleepUntil(DateTime dt) =>
timeIO.Bind(e => e.SleepUntil(dt));
/// <summary>
/// Pause a task until for a specified length of time
/// </summary>
[Pure, MethodImpl(EffOpt.mops)]
public static K<M, Unit> sleepFor(TimeSpan ts) =>
timeIO.Bind(e => e.SleepFor(ts));
}