diff --git a/showcases/data/Essential/Functions/Date/Basic/code.pure b/showcases/data/Essential/Functions/Date/Basic/code.pure new file mode 100644 index 000000000..5a40f450d --- /dev/null +++ b/showcases/data/Essential/Functions/Date/Basic/code.pure @@ -0,0 +1,51 @@ +Class examples::stringToDate::StringToDateSource +{ + sourceValue: String[0..1]; +} + +Class examples::stringToDate::StringToDateTarget +{ + targetValue: StrictDate[0..1]; +} + + +###Mapping +Mapping examples::stringToDate::StringToDateMapping +( + *examples::stringToDate::StringToDateTarget: Pure + { + ~src examples::stringToDate::StringToDateSource + targetValue: if( + $src.sourceValue->isEmpty(), + |[], + |$src.sourceValue->toOne()->parseDate()->cast( + @StrictDate + ) +) + } + + MappingTests + [ + test_1 + ( + query: |examples::stringToDate::StringToDateTarget.all()->graphFetch( + #{ + examples::stringToDate::StringToDateTarget{ + targetValue + } + }# +)->serialize( + #{ + examples::stringToDate::StringToDateTarget{ + targetValue + } + }# +); + data: + [ + + ]; + assert: '{"targetValue":"2022-02-17"}'; + ) + ] +) \ No newline at end of file diff --git a/showcases/data/Essential/Functions/Date/Basic/info.md b/showcases/data/Essential/Functions/Date/Basic/info.md new file mode 100644 index 000000000..6e09961f3 --- /dev/null +++ b/showcases/data/Essential/Functions/Date/Basic/info.md @@ -0,0 +1,6 @@ +--- +title: String Basic Functions +description: String to Date +--- + +Demonstrating how to convert a string into a StrictDate type using mappings that includes handling null/empty values. \ No newline at end of file