Skip to content

Commit

Permalink
Implement Morphir.SDK.LocalDate toISOString (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-corn authored Mar 20, 2024
1 parent 36bb033 commit c5a1cf7
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"src/Morphir/Examples/App/LetRecursionTests.elm": "34aca5346310d8874524854dd9c58e7b",
"src/Morphir/Examples/App/ListTests.elm": "d10ba935a4bea7fbed6431d5de9bd0b1",
"src/Morphir/Examples/App/LiteralTests.elm": "e7e578d1005014e3800a9e5058405152",
"src/Morphir/Examples/App/LocalDateTests.elm": "6bd03cb297186ae30d3a60891e73688b",
"src/Morphir/Examples/App/LocalDateTests.elm": "49dd757c3c3f8c333a4ee97d03623979",
"src/Morphir/Examples/App/LocalTimeTests.elm": "9e2e1cd8b89e5ddf4bdf655a2c5812fd",
"src/Morphir/Examples/App/MaybeTests.elm": "d25eeea002a4e4e153ae81c9acc2130b",
"src/Morphir/Examples/App/MyMap.elm": "81160d8bf93061cdf69d1eed29dc696f",
Expand All @@ -25,9 +25,9 @@
"src/Morphir/Examples/App/SdkBasicsTests.elm": "68b4fa58886ca3e42054852d917b33b1",
"src/Morphir/Examples/App/SetTests.elm": "7c4307aefe818e3ca4c3e576fed220c9",
"src/Morphir/Examples/App/SimpleTests.elm": "443d3bfdd8a53223afbcbe215b815099",
"src/Morphir/Examples/App/StringTests.elm": "c0e2dc1679e67a25bfc6650077ea08a5",
"src/Morphir/Examples/App/StringTests.elm": "616ac7d6808954716125790bf2b90674",
"src/Morphir/Examples/App/TestUtils.elm": "3072a79fadc6116b1dde77c7f424ca20",
"src/Morphir/Examples/App/TupleTests.elm": "ab771b0e379f4972f01632feb035f980",
"src/Morphir/Examples/App/TypeCheckerTests.elm": "3d3c59b81cfe90e371db9f0ebe21deed",
"src/Morphir/Examples/App/TypeCheckerTests.elm": "96704e08e7a877e9792ba2c2a4b0cf44",
"src/Morphir/Examples/App/UserDefinedReferenceTests.elm": "a99d0b2e4c311e6109a9c60751131f2d"
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,37 @@ dayOfWeekAsInputTest dayOfWeek =

Sunday ->
7


{-| Test: test input support for DayOfWeek enum
-}
dayOfWeekAsInputTest : DayOfWeek -> Int
dayOfWeekAsInputTest dayOfWeek =
case dayOfWeek of
Monday ->
1

Tuesday ->
2

Wednesday ->
3

Thursday ->
4

Friday ->
5

Saturday ->
6

Sunday ->
7


{-| Test: LocalDate:toISOString
-}
toISOStringTest : LocalDate -> String
toISOStringTest localDate =
toISOString localDate
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ stringConcat : List String -> String
stringConcat l =
concat l


{-|
Test: String/repeat
-}
stringRepeat : Int -> String -> String
stringRepeat : Int -> String -> String
stringRepeat i s =
repeat i s


{-|
Test: String/contains
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Morphir.Examples.App.TypeCheckerTests exposing (..)
import Morphir.Examples.App.ExampleModule exposing (OpaqueInt, wrap, unwrap)

import Morphir.Examples.App.ExampleModule exposing (OpaqueInt, unwrap, wrap)


intToInt : Int -> Int
intToInt x =
Expand Down Expand Up @@ -35,19 +37,31 @@ twoArgEntry : Int -> String -> ( Int, String )
twoArgEntry i s =
( i, s )


acceptOpaque : OpaqueInt -> Int
acceptOpaque o = unwrap o
acceptOpaque o =
unwrap o


returnOpaque : Int -> OpaqueInt
returnOpaque i = wrap i
returnOpaque i =
wrap i


type alias AliasedOpaque =
OpaqueInt

type alias AliasedOpaque = OpaqueInt

dealiasOpaque : AliasedOpaque -> OpaqueInt
dealiasOpaque a = a
dealiasOpaque a =
a


aliasOpaque : OpaqueInt -> AliasedOpaque
aliasOpaque a = a
aliasOpaque a =
a


aliasedOpaqueTest : OpaqueInt -> AliasedOpaque
aliasedOpaqueTest a = dealiasOpaque a |> unwrap |> \x -> x + 1 |> wrap
aliasedOpaqueTest a =
dealiasOpaque a |> unwrap |> (\x -> x + 1 |> wrap)
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,8 @@ object EvaluatorMDMTests extends MorphirBaseSpec {
testEval("day")("localDateTests", "dayTest", localDate)(Data.Int(20)),
testEval("dayOfWeek")("localDateTests", "dayOfWeekTest", localDate)(
Data.DayOfWeek(java.time.DayOfWeek.SATURDAY)
)
),
testEval("toISOString")("localDateTests", "toISOStringTest", localDate)(Data.String("1900-01-20"))
),
suite("LocalTime")(
testEvaluation("fromMilliseconds")("localTimeTests", "fromMillisecondsTest")(Data.LocalTime(localTime)),
Expand Down
3 changes: 2 additions & 1 deletion morphir/src/org/finos/morphir/ir/sdk/LocalDate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ object LocalDate extends MorphirIRSdkModule("LocalDate") {
vSpec("addDays", "offset" -> intType, "startDate" -> localDateType)(localDateType),
vSpec("addWeeks", "offset" -> intType, "startDate" -> localDateType)(localDateType),
vSpec("addMonths", "offset" -> intType, "startDate" -> localDateType)(localDateType),
vSpec("addYears", "offset" -> intType, "startDate" -> localDateType)(localDateType)
vSpec("addYears", "offset" -> intType, "startDate" -> localDateType)(localDateType),
vSpec("toISOString", "date" -> localDateType)(stringType)
)
)

Expand Down
3 changes: 2 additions & 1 deletion morphir/src/org/finos/morphir/runtime/NativeSDK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ object NativeSDK {
NativeFunctionAdapter.Fun2(LocalDateSDK.diffInDays),
NativeFunctionAdapter.Fun2(LocalDateSDK.fromOrdinalDate),
NativeFunctionAdapter.Fun3(LocalDateSDK.fromCalendarDate),
NativeFunctionAdapter.Fun3(LocalDateSDK.fromParts)
NativeFunctionAdapter.Fun3(LocalDateSDK.fromParts),
NativeFunctionAdapter.Fun1(LocalDateSDK.toISOString)
)

private val enumSDKConstructor = SDKConstructor(scala.List())
Expand Down
5 changes: 5 additions & 0 deletions morphir/src/org/finos/morphir/runtime/sdk/LocalDateSDK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,9 @@ object LocalDateSDK {
(_: NativeContext) => (localDate: RTValue.LocalDate) =>
RTValue.DayOfWeek.fromJavaDayOfWeek(localDate.value.getDayOfWeek)
}

val toISOString = DynamicNativeFunction1("toISOString") {
(_: NativeContext) => (localDate: RTValue.LocalDate) =>
RTValue.Primitive.String(localDate.value.format(JDateTimeFormatter.ISO_LOCAL_DATE))
}
}

0 comments on commit c5a1cf7

Please sign in to comment.