-
Notifications
You must be signed in to change notification settings - Fork 24
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
Showing
6 changed files
with
64 additions
and
9 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
26 changes: 26 additions & 0 deletions
26
Tokenizer.Tests/Transformers/ToDateTimeUtcTransformerTest.cs
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,26 @@ | ||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace Tokens.Transformers | ||
{ | ||
[TestFixture] | ||
public class ToDateTimeUtcTransformerTest | ||
{ | ||
private ToDateTimeUtcTransformer @operator; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
@operator = new ToDateTimeUtcTransformer(); | ||
} | ||
|
||
[Test] | ||
public void TestParseDateSetsKindToUtc() | ||
{ | ||
var result = (DateTime) @operator.Transform("2014-01-01", "yyyy-MM-dd"); | ||
|
||
Assert.AreEqual(new DateTime(2014, 1, 1), result); | ||
Assert.AreEqual(DateTimeKind.Utc, result.Kind); | ||
} | ||
} | ||
} |
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
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,22 @@ | ||
using System; | ||
|
||
namespace Tokens.Transformers | ||
{ | ||
/// <summary> | ||
/// Converts the token value to a <see cref="DateTime"/> in UTC format | ||
/// </summary> | ||
public class ToDateTimeUtcTransformer : ITokenTransformer | ||
{ | ||
public object Transform(object value, params string[] args) | ||
{ | ||
if (value == null) return string.Empty; | ||
|
||
if (ToDateTimeTransformer.ToDateTime(value, args, out var result)) | ||
{ | ||
value = DateTime.SpecifyKind(result, DateTimeKind.Utc); | ||
} | ||
|
||
return value; | ||
} | ||
} | ||
} |