-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/native_functions_for_expressions_(#468)' into d…
…evelop
- Loading branch information
Showing
38 changed files
with
866 additions
and
643 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
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
29 changes: 0 additions & 29 deletions
29
NBi.Core/Transformation/Transformer/Native/BlankToEmpty.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
148 changes: 148 additions & 0 deletions
148
NBi.Core/Transformation/Transformer/Native/DateTime/DateTimeTransformations.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,148 @@ | ||
using NBi.Core.Scalar.Casting; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NBi.Core.Transformation.Transformer.Native | ||
{ | ||
abstract class AbstractDateTimeTransformation : INativeTransformation | ||
{ | ||
|
||
public object Evaluate(object value) | ||
{ | ||
switch (value) | ||
{ | ||
case null: return EvaluateNull(); | ||
case DBNull dbnull: return EvaluateNull(); | ||
case DateTime dt: return EvaluateDateTime(dt); | ||
default: return EvaluateUncasted(value); | ||
} | ||
} | ||
|
||
private object EvaluateUncasted(object value) | ||
{ | ||
if (value as string == "null") | ||
EvaluateNull(); | ||
|
||
var caster = new DateTimeCaster(); | ||
var dateTime = caster.Execute(value); | ||
return EvaluateDateTime(dateTime); | ||
} | ||
|
||
protected virtual object EvaluateNull() => null; | ||
protected abstract object EvaluateDateTime(DateTime value); | ||
} | ||
|
||
class DateTimeToDate : AbstractDateTimeTransformation | ||
{ | ||
protected override object EvaluateDateTime(DateTime value) => value.Date; | ||
} | ||
|
||
class DateToAge : AbstractDateTimeTransformation | ||
{ | ||
protected override object EvaluateNull() => 0; | ||
protected override object EvaluateDateTime(DateTime value) | ||
{ | ||
// Save today's date. | ||
var today = DateTime.Today; | ||
// Calculate the age. | ||
var age = today.Year - value.Year; | ||
// Go back to the year the person was born in case of a leap year | ||
return value.AddYears(age) > today ? age-- : age; | ||
} | ||
} | ||
|
||
class DateTimeToFirstOfMonth : AbstractDateTimeTransformation | ||
{ | ||
protected override object EvaluateDateTime(DateTime value) => new DateTime(value.Year, value.Month, 1); | ||
} | ||
|
||
class DateTimeToFirstOfYear : AbstractDateTimeTransformation | ||
{ | ||
protected override object EvaluateDateTime(DateTime value) => new DateTime(value.Year, 1, 1); | ||
} | ||
|
||
class DateTimeToLastOfMonth : AbstractDateTimeTransformation | ||
{ | ||
protected override object EvaluateDateTime(DateTime value) => new DateTime(value.Year, value.Month, 1).AddMonths(1).AddDays(-1); | ||
} | ||
|
||
class DateTimeToLastOfYear : AbstractDateTimeTransformation | ||
{ | ||
protected override object EvaluateDateTime(DateTime value) => new DateTime(value.Year, 12, 31); | ||
} | ||
|
||
class DateTimeToNextDay : AbstractDateTimeTransformation | ||
{ | ||
protected override object EvaluateDateTime(DateTime value) => value.AddDays(1); | ||
} | ||
|
||
class DateTimeToNextMonth : AbstractDateTimeTransformation | ||
{ | ||
protected override object EvaluateDateTime(DateTime value) => value.AddMonths(1); | ||
} | ||
|
||
class DateTimeToNextYear : AbstractDateTimeTransformation | ||
{ | ||
protected override object EvaluateDateTime(DateTime value) => value.AddYears(1); | ||
} | ||
|
||
class DateTimeToPreviousDay : AbstractDateTimeTransformation | ||
{ | ||
protected override object EvaluateDateTime(DateTime value) => value.AddDays(-1); | ||
} | ||
|
||
class DateTimeToPreviousMonth : AbstractDateTimeTransformation | ||
{ | ||
protected override object EvaluateDateTime(DateTime value) => value.AddMonths(-1); | ||
} | ||
|
||
class DateTimeToPreviousYear : AbstractDateTimeTransformation | ||
{ | ||
protected override object EvaluateDateTime(DateTime value) => value.AddYears(-1); | ||
} | ||
|
||
class DateTimeToClip : AbstractDateTimeTransformation | ||
{ | ||
public DateTime Min { get; } | ||
public DateTime Max { get; } | ||
|
||
public DateTimeToClip(string min, string max) | ||
{ | ||
var caster = new DateTimeCaster(); | ||
Min = caster.Execute(min); | ||
Max = caster.Execute(max); | ||
} | ||
|
||
protected override object EvaluateDateTime(DateTime value) => (value < Min) ? Min : (value > Max) ? Max : value; | ||
} | ||
|
||
class DateTimeToSetTime : AbstractDateTimeTransformation | ||
{ | ||
public TimeSpan Instant { get; } | ||
|
||
public DateTimeToSetTime(string instant) | ||
{ | ||
Instant = TimeSpan.Parse(instant); | ||
} | ||
|
||
protected override object EvaluateDateTime(DateTime value) | ||
=> new DateTime(value.Year, value.Month, value.Day, Instant.Hours, Instant.Minutes, Instant.Seconds); | ||
} | ||
|
||
class NullToDate : AbstractDateTimeTransformation | ||
{ | ||
public DateTime Default { get; } | ||
|
||
public NullToDate(string dt) | ||
{ | ||
var caster = new DateTimeCaster(); | ||
Default = caster.Execute(dt); | ||
} | ||
|
||
protected override object EvaluateNull() => Default; | ||
protected override object EvaluateDateTime(DateTime value) => value; | ||
} | ||
} |
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
24 changes: 0 additions & 24 deletions
24
NBi.Core/Transformation/Transformer/Native/DateTimeToDate.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.