How to use EvaluateNull method of NBi.Core.Transformation.Transformer.Native.DateTimeToDate class

Best NBi code snippet using NBi.Core.Transformation.Transformer.Native.DateTimeToDate.EvaluateNull

DateTimeTransformations.cs

Source:DateTimeTransformations.cs Github

copy

Full Screen

...13 public object Evaluate(object value)14 {15 switch (value)16 {17 case null: return EvaluateNull();18 case DBNull _: return EvaluateNull();19 case DateTime dt: return EvaluateDateTime(dt);20 default: return EvaluateUncasted(value);21 }22 }23 private object EvaluateUncasted(object value)24 {25 if (value as string == "(null)" || (value is string && string.IsNullOrEmpty(value as string)))26 return EvaluateNull();27 var caster = new DateTimeCaster();28 var dateTime = caster.Execute(value);29 return EvaluateDateTime(dateTime);30 }31 protected virtual object EvaluateNull() => null;32 protected abstract object EvaluateDateTime(DateTime value);33 }34 class DateTimeToDate : AbstractDateTimeTransformation35 {36 protected override object EvaluateDateTime(DateTime value) => value.Date;37 }38 class DateToAge : AbstractDateTimeTransformation39 {40 protected override object EvaluateNull() => 0;41 protected override object EvaluateDateTime(DateTime value)42 {43 // Save today's date.44 var today = DateTime.Today;45 // Calculate the age.46 var age = today.Year - value.Year;47 // Go back to the year the person was born in case of a leap year48 return value.AddYears(age) > today ? age-- : age;49 }50 }51 class DateTimeToFirstOfMonth : AbstractDateTimeTransformation52 {53 protected override object EvaluateDateTime(DateTime value) => new DateTime(value.Year, value.Month, 1);54 }55 class DateTimeToFirstOfYear : AbstractDateTimeTransformation56 {57 protected override object EvaluateDateTime(DateTime value) => new DateTime(value.Year, 1, 1);58 }59 class DateTimeToLastOfMonth : AbstractDateTimeTransformation60 {61 protected override object EvaluateDateTime(DateTime value) => new DateTime(value.Year, value.Month, 1).AddMonths(1).AddDays(-1);62 }63 class DateTimeToLastOfYear : AbstractDateTimeTransformation64 {65 protected override object EvaluateDateTime(DateTime value) => new DateTime(value.Year, 12, 31);66 }67 class DateTimeToNextDay : AbstractDateTimeTransformation68 {69 protected override object EvaluateDateTime(DateTime value) => value.AddDays(1);70 }71 class DateTimeToNextMonth : AbstractDateTimeTransformation72 {73 protected override object EvaluateDateTime(DateTime value) => value.AddMonths(1);74 }75 class DateTimeToNextYear : AbstractDateTimeTransformation76 {77 protected override object EvaluateDateTime(DateTime value) => value.AddYears(1);78 }79 class DateTimeToPreviousDay : AbstractDateTimeTransformation80 {81 protected override object EvaluateDateTime(DateTime value) => value.AddDays(-1);82 }83 class DateTimeToPreviousMonth : AbstractDateTimeTransformation84 {85 protected override object EvaluateDateTime(DateTime value) => value.AddMonths(-1);86 }87 class DateTimeToPreviousYear : AbstractDateTimeTransformation88 {89 protected override object EvaluateDateTime(DateTime value) => value.AddYears(-1);90 }91 class DateTimeToClip : AbstractDateTimeTransformation92 {93 public IScalarResolver<DateTime> Min { get; }94 public IScalarResolver<DateTime> Max { get; }95 public DateTimeToClip(IScalarResolver<DateTime> min, IScalarResolver<DateTime> max)96 => (Min, Max) = (min, max);97 protected override object EvaluateDateTime(DateTime value)98 => (value < Min.Execute()) ? Min.Execute() : (value > Max.Execute()) ? Max.Execute() : value;99 }100 class DateTimeToSetTime : AbstractDateTimeTransformation101 {102 public IScalarResolver<string> Instant { get; }103 public DateTimeToSetTime(IScalarResolver<string> instant)104 => Instant = instant;105 protected override object EvaluateDateTime(DateTime value)106 {107 var time = TimeSpan.Parse(Instant.Execute());108 return new DateTime(value.Year, value.Month, value.Day, time.Hours, time.Minutes, time.Seconds);109 }110 }111 class NullToDate : AbstractDateTimeTransformation112 {113 public IScalarResolver<DateTime> Default { get; }114 public NullToDate(IScalarResolver<DateTime> dt)115 => Default = dt;116 protected override object EvaluateNull() => Default.Execute();117 protected override object EvaluateDateTime(DateTime value) => value;118 }119 class DateTimeToFloorHour : AbstractDateTimeTransformation120 {121 protected override object EvaluateDateTime(DateTime value)122 => value.AddTicks(-1 * (value.Ticks % TimeSpan.TicksPerHour));123 }124 class DateTimeToCeilingHour : AbstractDateTimeTransformation125 {126 protected override object EvaluateDateTime(DateTime value)127 => value.AddTicks(TimeSpan.TicksPerHour - (value.Ticks % TimeSpan.TicksPerHour == 0 ? TimeSpan.TicksPerHour : value.Ticks % TimeSpan.TicksPerHour));128 }129 class DateTimeToFloorMinute : AbstractDateTimeTransformation130 {...

Full Screen

Full Screen

EvaluateNull

Using AI Code Generation

copy

Full Screen

1DateTimeToDate transformer = new DateTimeToDate();2var result = transformer.EvaluateNull("2015-01-01 12:00:00");3DateTimeToTime transformer = new DateTimeToTime();4var result = transformer.EvaluateNull("2015-01-01 12:00:00");5DateTimeToYear transformer = new DateTimeToYear();6var result = transformer.EvaluateNull("2015-01-01 12:00:00");7DateTimeToMonth transformer = new DateTimeToMonth();8var result = transformer.EvaluateNull("2015-01-01 12:00:00");9DateTimeToDay transformer = new DateTimeToDay();10var result = transformer.EvaluateNull("2015-01-01 12:00:00");11DateTimeToHour transformer = new DateTimeToHour();12var result = transformer.EvaluateNull("2015-01-01 12:00:00");13DateTimeToMinute transformer = new DateTimeToMinute();14var result = transformer.EvaluateNull("2015-01-01 12:00:00");15DateTimeToSecond transformer = new DateTimeToSecond();16var result = transformer.EvaluateNull("2015-01-01 12:00:00");

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run NBi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful