-
Notifications
You must be signed in to change notification settings - Fork 2
/
Now.cs
59 lines (55 loc) · 1.41 KB
/
Now.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
53
54
55
56
57
58
59
using BlocklyNet.Core.Model;
using BlocklyNet.Extensions.Builder;
namespace BlocklyNet.Extensions;
/// <summary>
/// Get the current time as a string.
/// </summary>
[CustomBlock(
"get_date_time",
"",
@"{
""message0"": ""Now %1 %2 %3"",
""args0"": [
{
""type"": ""input_dummy""
},
{
""type"": ""field_label_serializable"",
""name"": ""FORMAT"",
""text"": ""Format""
},
{
""type"": ""input_value"",
""name"": ""FORMAT"",
""check"": ""String""
}
],
""output"": null,
""colour"": ""#107159"",
""tooltip"": ""Get the current time"",
""helpUrl"": """"
}",
@"{
""inputs"": {
""FORMAT"": {
""shadow"": {
""type"": ""text"",
""fields"": {
""TEXT"": ""dd.MM.yyyy HH:mm:ss""
}
}
}
}
}"
)]
public class Now : Block
{
/// <inheritdoc/>
public override async Task<object?> EvaluateAsync(Context context)
{
var format = await Values.EvaluateAsync<string>("FORMAT", context);
return string.IsNullOrWhiteSpace(format)
? (double)DateTime.Now.Ticks
: DateTime.Now.ToString(format);
}
}