Skip to content

Commit

Permalink
Morphir.SDK.LocalDate addDays, addYears (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-corn authored Mar 8, 2024
1 parent 216543d commit e24aa9f
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"src/Morphir/Examples/App/CharTests.elm": "6bbca43824e960ace71170da4a931454",
"src/Morphir/Examples/App/CharTests.elm": "59003691272339f9f27f6972af241a90",
"src/Morphir/Examples/App/ConstructorTests.elm": "0855b8930e83e1b1c4670fd43ab75a45",
"src/Morphir/Examples/App/CurrentTest.elm": "cb91097f6ef5126d75fa93063072a328",
"src/Morphir/Examples/App/DecimalTests.elm": "1d683692eb14926bbc6cf46cc16d3304",
Expand All @@ -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": "483e00c25f78b4becdea7d9bf1cc3810",
"src/Morphir/Examples/App/LocalDateTests.elm": "6bd03cb297186ae30d3a60891e73688b",
"src/Morphir/Examples/App/LocalTimeTests.elm": "9e2e1cd8b89e5ddf4bdf655a2c5812fd",
"src/Morphir/Examples/App/MaybeTests.elm": "d25eeea002a4e4e153ae81c9acc2130b",
"src/Morphir/Examples/App/MyMap.elm": "81160d8bf93061cdf69d1eed29dc696f",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,131 +5,169 @@ import Morphir.SDK.Char as Char exposing (..)


{-|
Test: Char/isUpper
expected('A') = True
expected('w') = False
expected('1') = False
expected('Σ') = False
-}
charIsUpperTest : Char -> Bool
charIsUpperTest ch =
isUpper ch


{-|
Test: Char/isLower
expected('w') = True
expected('A') = False
expected('0') = False
expected('π') = False
-}
charIsLowerTest: Char -> Bool
charIsLowerTest : Char -> Bool
charIsLowerTest ch =
isLower ch


{-|
Test: Char/isAlpha
expected('z') = True
expected('A') = True
expected('1') = False
expected('π') = False
-}
charIsAlphaTest: Char -> Bool
charIsAlphaTest ch = isAlpha ch
charIsAlphaTest : Char -> Bool
charIsAlphaTest ch =
isAlpha ch


{-|
Test: Char/isAlphaNum
expected('z') = True
expected('A') = False
expected('1') = True
expected('π') = False
-}
charIsAlphaNumTest: Char -> Bool
charIsAlphaNumTest ch = isAlphaNum ch
charIsAlphaNumTest : Char -> Bool
charIsAlphaNumTest ch =
isAlphaNum ch


{-|
Test: Char/isDigit
expected('1') = True
expected('A') = False
expected('π') = False
-}
charIsDigitTest: Char -> Bool
charIsDigitTest ch = isDigit ch
charIsDigitTest : Char -> Bool
charIsDigitTest ch =
isDigit ch


{-|
Test: Char/isOctDigit
expected('1') = True
expected('8') = False
expected('A') = False
expected('π') = False
-}
charIsOctDigitTest: Char -> Bool
charIsOctDigitTest ch = isOctDigit ch
charIsOctDigitTest : Char -> Bool
charIsOctDigitTest ch =
isOctDigit ch


{-|
Test: Char/isHexDigit
expected('1') = True
expected('A') = True
expected('f') = True
expected('g') = False
expected('π') = False
-}
charIsHexDigitTest: Char -> Bool
charIsHexDigitTest ch = isHexDigit ch
charIsHexDigitTest : Char -> Bool
charIsHexDigitTest ch =
isHexDigit ch


{-|
Test: Char/toUpper
expected('z') = 'Z'
-}
charToUpperTest: Char -> Char
charToUpperTest ch = toUpper ch
charToUpperTest : Char -> Char
charToUpperTest ch =
toUpper ch


{-|
Test: Char/toLower
expected('Z') = 'z'
-}
charToLowerTest: Char -> Char
charToLowerTest ch = toLower ch
charToLowerTest : Char -> Char
charToLowerTest ch =
toLower ch


{-|
Test: Char/toLocaleUpper
expected('z') = 'Z'
-}
charToLocaleUpperTest: Char -> Char
charToLocaleUpperTest ch = toLocaleUpper ch
charToLocaleUpperTest : Char -> Char
charToLocaleUpperTest ch =
toLocaleUpper ch


{-|
Test: Char/toLocaleLower
expected('Z') = 'z'
-}
charToLocaleLowerTest: Char -> Char
charToLocaleLowerTest ch = toLocaleLower ch
charToLocaleLowerTest : Char -> Char
charToLocaleLowerTest ch =
toLocaleLower ch


{-|
Test: Char/toCode
expected('A') = 65
expected('B') = 66
expected('木') = 0x6728
-}
charToCodeTest: Char -> Int
charToCodeTest ch = toCode ch
charToCodeTest : Char -> Int
charToCodeTest ch =
toCode ch


{-|
Test: Char/fromCode
expected(65) = 'A'
expected(66) = 'B'
expected(0x6728) = '木'
expected(-1) = '�'
-}
charFromCodeTest: Int -> Char
charFromCodeTest int = fromCode int
charFromCodeTest : Int -> Char
charFromCodeTest int =
fromCode int
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ fromPartsInvalidTest ctx =
(fromParts 1900 1 9999)


{-| Test: LocalDate:addDays
input = 2, 1900-01-20
expected = 1900-01-22
-}
addDaysTest : Int -> LocalDate -> LocalDate
addDaysTest weeks date =
addDays weeks date


{-| Test: LocalDate:addWeeks
input = 2, 1900-01-20
expected = 1900-02-03
Expand All @@ -31,6 +40,15 @@ addWeeksTest weeks date =
addWeeks weeks date


{-| Test: LocalDate:addYears
input = 2, 1900-01-20
expected = 1902-01-20
-}
addYearsTest : Int -> LocalDate -> LocalDate
addYearsTest weeks date =
addYears weeks date


{-| Test: LocalDate:diffInDays
input = 1900-01-20, 1902-10-16
expected = -999
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,9 +1120,15 @@ object EvaluatorMDMTests extends MorphirBaseSpec {
)
)
),
testEvalMultiple("addDays")("localDateTests", "addDaysTest", List(2, localDate))(
Data.LocalDate(localDate.plusDays(2))
),
testEvalMultiple("addWeeks")("localDateTests", "addWeeksTest", List(2, localDate))(
Data.LocalDate(localDate.plusWeeks(2))
),
testEvalMultiple("addYears")("localDateTests", "addYearsTest", List(2, localDate))(
Data.LocalDate(localDate.plusYears(2))
),
testEvalMultiple("diffInDays")("localDateTests", "diffInDaysTest", List(localDate, localDate.plusDays(999)))(
Data.Int(999)
),
Expand Down
18 changes: 10 additions & 8 deletions morphir/src/org/finos/morphir/runtime/NativeSDK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,19 @@ object NativeSDK {

case object LocalDate extends SdkModuleDescriptor(moduleName = "LocalDate") {
val functions: List[NativeFunctionAdapter] = scala.List(
NativeFunctionAdapter.Fun3(LocalDateSDK.fromCalendarDate),
NativeFunctionAdapter.Fun2(LocalDateSDK.fromOrdinalDate),
NativeFunctionAdapter.Fun3(LocalDateSDK.fromParts),
NativeFunctionAdapter.Fun2(LocalDateSDK.addWeeks),
NativeFunctionAdapter.Fun2(LocalDateSDK.diffInDays),
NativeFunctionAdapter.Fun1(LocalDateSDK.day),
NativeFunctionAdapter.Fun1(LocalDateSDK.dayOfWeek),
NativeFunctionAdapter.Fun1(LocalDateSDK.fromISO),
NativeFunctionAdapter.Fun1(LocalDateSDK.year),
NativeFunctionAdapter.Fun1(LocalDateSDK.month),
NativeFunctionAdapter.Fun1(LocalDateSDK.monthNumber),
NativeFunctionAdapter.Fun1(LocalDateSDK.day),
NativeFunctionAdapter.Fun1(LocalDateSDK.dayOfWeek)
NativeFunctionAdapter.Fun1(LocalDateSDK.year),
NativeFunctionAdapter.Fun2(LocalDateSDK.addDays),
NativeFunctionAdapter.Fun2(LocalDateSDK.addWeeks),
NativeFunctionAdapter.Fun2(LocalDateSDK.addYears),
NativeFunctionAdapter.Fun2(LocalDateSDK.diffInDays),
NativeFunctionAdapter.Fun2(LocalDateSDK.fromOrdinalDate),
NativeFunctionAdapter.Fun3(LocalDateSDK.fromCalendarDate),
NativeFunctionAdapter.Fun3(LocalDateSDK.fromParts)
)

private val enumSDKConstructor = SDKConstructor(scala.List())
Expand Down
10 changes: 10 additions & 0 deletions morphir/src/org/finos/morphir/runtime/sdk/LocalDateSDK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,21 @@ object LocalDateSDK {
}
}

val addDays = DynamicNativeFunction2("addDays") {
(_: NativeContext) => (weeksArg: RTValue.Primitive.Int, localDateArg: RTValue.LocalDate) =>
update(localDateArg)(_.plusDays(weeksArg.value.toLong))
}

val addWeeks = DynamicNativeFunction2("addWeeks") {
(_: NativeContext) => (weeksArg: RTValue.Primitive.Int, localDateArg: RTValue.LocalDate) =>
update(localDateArg)(_.plusWeeks(weeksArg.value.toLong))
}

val addYears = DynamicNativeFunction2("addYears") {
(_: NativeContext) => (weeksArg: RTValue.Primitive.Int, localDateArg: RTValue.LocalDate) =>
update(localDateArg)(_.plusYears(weeksArg.value.toLong))
}

val diffInDays = DynamicNativeFunction2("diffInDays") {
(_: NativeContext) => (localDateArg1: RTValue.LocalDate, localDateArg2: RTValue.LocalDate) =>
{
Expand Down

0 comments on commit e24aa9f

Please sign in to comment.