Skip to content

Commit

Permalink
review date showcase (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
kelly-thai authored Aug 22, 2024
1 parent 28a3330 commit c6b63bb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
51 changes: 51 additions & 0 deletions showcases/data/Essential/Functions/Date/Basic/code.pure
Original file line number Diff line number Diff line change
@@ -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:
[
<Object, JSON, examples::stringToDate::StringToDateSource, '{"sourceValue":"2022-02-17"}'>
];
assert: '{"targetValue":"2022-02-17"}';
)
]
)
6 changes: 6 additions & 0 deletions showcases/data/Essential/Functions/Date/Basic/info.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit c6b63bb

Please sign in to comment.