Skip to content

Commit

Permalink
Merge branch 'feature/dateTime_transformation_floor-ceiling_(#510)' i…
Browse files Browse the repository at this point in the history
…nto develop
  • Loading branch information
Cédric L. Charlier committed Aug 24, 2019
2 parents 2c00d68 + abd4707 commit c62d423
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,28 @@ public NullToDate(string dt)
protected override object EvaluateNull() => Default;
protected override object EvaluateDateTime(DateTime value) => value;
}

class DateTimeToFloorHour : AbstractDateTimeTransformation
{
protected override object EvaluateDateTime(DateTime value)
=> value.AddTicks(-1 * (value.Ticks % TimeSpan.TicksPerHour));
}

class DateTimeToCeilingHour : AbstractDateTimeTransformation
{
protected override object EvaluateDateTime(DateTime value)
=> value.AddTicks(TimeSpan.TicksPerHour - (value.Ticks % TimeSpan.TicksPerHour == 0 ? TimeSpan.TicksPerHour : value.Ticks % TimeSpan.TicksPerHour));
}

class DateTimeToFloorMinute : AbstractDateTimeTransformation
{
protected override object EvaluateDateTime(DateTime value)
=> value.AddTicks(-1 * (value.Ticks % TimeSpan.TicksPerMinute));
}

class DateTimeToCeilingMinute : AbstractDateTimeTransformation
{
protected override object EvaluateDateTime(DateTime value)
=> value.AddTicks(TimeSpan.TicksPerMinute - (value.Ticks % TimeSpan.TicksPerMinute == 0 ? TimeSpan.TicksPerMinute : value.Ticks % TimeSpan.TicksPerMinute));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public void Execute_DateTimeToNextYear_Valid(object value, DateTime expected)
[TestCase("2019-03-11", "2019-03-10")]
[TestCase("2019-02-01", "2019-01-31")]
[TestCase("2020-03-01", "2020-02-29")]
[TestCase("2020-03-01 17:30:12", "2020-02-29 17:30:12")]
public void Execute_DateTimeToPreviousDay_Valid(object value, DateTime expected)
{
var function = new DateTimeToPreviousDay();
Expand All @@ -114,6 +115,7 @@ public void Execute_DateTimeToPreviousDay_Valid(object value, DateTime expected)
[TestCase("2019-03-11", "2019-02-11")]
[TestCase("2019-03-31", "2019-02-28")]
[TestCase("2020-01-31", "2019-12-31")]
[TestCase("2020-01-31 17:30:12", "2019-12-31 17:30:12")]
public void Execute_DateTimeToPreviousMonth_Valid(object value, DateTime expected)
{
var function = new DateTimeToPreviousMonth();
Expand All @@ -140,5 +142,53 @@ public void Execute_DateTimeToSetTime_Valid(object value, string instant, DateTi
var result = function.Evaluate(value);
Assert.That(result, Is.EqualTo(expected));
}

[Test]
[TestCase("2019-03-11 17:00:00", "2019-03-11 17:00:00")]
[TestCase("2019-03-11 17:20:00", "2019-03-11 17:00:00")]
[TestCase("2019-03-11 17:20:24", "2019-03-11 17:00:00")]
[TestCase("2019-03-11 17:40:00", "2019-03-11 17:00:00")]
public void Execute_DateTimeToFloorHour_Valid(object value, DateTime expected)
{
var function = new DateTimeToFloorHour();
var result = function.Evaluate(value);
Assert.That(result, Is.EqualTo(expected));
}

[Test]
[TestCase("2019-03-11 17:00:00", "2019-03-11 17:00:00")]
[TestCase("2019-03-11 17:20:00", "2019-03-11 18:00:00")]
[TestCase("2019-03-11 17:20:24", "2019-03-11 18:00:00")]
[TestCase("2019-03-11 17:40:00", "2019-03-11 18:00:00")]
public void Execute_DateTimeToCeilingHour_Valid(object value, DateTime expected)
{
var function = new DateTimeToCeilingHour();
var result = function.Evaluate(value);
Assert.That(result, Is.EqualTo(expected));
}

[Test]
[TestCase("2019-03-11 17:00:00", "2019-03-11 17:00:00")]
[TestCase("2019-03-11 17:20:00", "2019-03-11 17:20:00")]
[TestCase("2019-03-11 17:20:24.120", "2019-03-11 17:20:00")]
[TestCase("2019-03-11 17:40:59", "2019-03-11 17:40:00")]
public void Execute_DateTimeToFloorMinute_Valid(object value, DateTime expected)
{
var function = new DateTimeToFloorMinute();
var result = function.Evaluate(value);
Assert.That(result, Is.EqualTo(expected));
}

[Test]
[TestCase("2019-03-11 17:00:00", "2019-03-11 17:00:00")]
[TestCase("2019-03-11 17:20:00", "2019-03-11 17:20:00")]
[TestCase("2019-03-11 17:20:24.120", "2019-03-11 17:21:00")]
[TestCase("2019-03-11 17:59:59", "2019-03-11 18:00:00")]
public void Execute_DateTimeToCeilingMinute_Valid(object value, DateTime expected)
{
var function = new DateTimeToCeilingMinute();
var result = function.Evaluate(value);
Assert.That(result, Is.EqualTo(expected));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public void Instantiate_ExistingWithParametersAndSpaces_CorrectType()
[TestCase("dateTime-to-previous-month")]
[TestCase("dateTime-to-next-year")]
[TestCase("dateTime-to-previous-year")]
[TestCase("dateTime-to-floor-hour")]
[TestCase("dateTime-to-ceiling-hour")]
[TestCase("dateTime-to-floor-minute")]
[TestCase("dateTime-to-ceiling-minute")]
[TestCase("dateTime-to-set-time(07:00:00)")]
[TestCase("numeric-to-round(5)")]
[TestCase("numeric-to-floor")]
Expand Down
4 changes: 4 additions & 0 deletions NBi.Xml/Schema/BaseType.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,10 @@
<xs:enumeration value="dateTime-to-previous-month"/>
<xs:enumeration value="dateTime-to-next-year"/>
<xs:enumeration value="dateTime-to-previous-year"/>
<xs:enumeration value="dateTime-to-floor-hour"/>
<xs:enumeration value="dateTime-to-ceiling-hour"/>
<xs:enumeration value="dateTime-to-floor-minute"/>
<xs:enumeration value="dateTime-to-ceiling-minute"/>
<xs:enumeration value="dateTime-to-set-time("/>
<xs:enumeration value="numeric-to-round("/>
<xs:enumeration value="numeric-to-floor"/>
Expand Down

0 comments on commit c62d423

Please sign in to comment.