-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb46ff7
commit caeeac6
Showing
2 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
module Morphir.SDK.LocalDate exposing (LocalDate) | ||
|
||
-- This is a temporary stub until we get into more requirements | ||
type LocalDate = LocalDate | ||
|
||
|
||
|
||
{- | ||
module Morphir.SDK.LocalDate exposing (Date, Month, Unit, fromCalendarDate, add) | ||
-- ( Date | ||
-- , Month, Weekday | ||
-- , today, fromPosix, fromCalendarDate, fromWeekDate, fromOrdinalDate, fromIsoString, fromRataDie | ||
-- , toIsoString, toRataDie | ||
-- , year, month, day, weekYear, weekNumber, weekday, ordinalDay, quarter, monthNumber, weekdayNumber | ||
-- , format | ||
-- , Language, formatWithLanguage | ||
-- , Unit(..), add, diff | ||
-- , Interval(..), ceiling, floor | ||
-- , range | ||
-- , compare, isBetween, min, max, clamp | ||
-- , monthToNumber, numberToMonth, weekdayToNumber, numberToWeekday | ||
-- ) | ||
{-| A `Date` is a representation of a day of the calendar without consideration for location. | ||
This module defines local date operations. | ||
@docs Date | ||
-} | ||
import Morphir.SDK.Int exposing (Int) | ||
-- import Date exposing (Date, Month, Unit(..)) | ||
import Date | ||
{-| Represents a date using the Rata Die system. | ||
This has the advantage of making Date comparable since Int is comparable. | ||
-} | ||
type alias Date = | ||
Date.Date | ||
type alias Month = | ||
Date.Month | ||
type alias Unit = | ||
Date.Unit | ||
fromCalendarDate : Int -> Month -> Int -> Date | ||
fromCalendarDate = | ||
Date.fromCalendarDate | ||
-- Maths -- | ||
add : Unit -> Int -> Date -> Date | ||
add = Date.add | ||
-- year : Date -> Int | ||
-- year ld = | ||
-- Date.year ld | ||
-- month : Date -> Int | ||
-- month ld = | ||
-- native | ||
-- (ld | ||
-- |> Date.fromRataDie | ||
-- |> Date.monthNumber | ||
-- ) | ||
-- plusMonths : Int -> Date -> Date | ||
-- plusMonths monthCount ld = | ||
-- native | ||
-- (ld | ||
-- |> Date.fromRataDie | ||
-- |> Date.add Date.Months monthCount | ||
-- |> Date.toRataDie | ||
-- ) | ||
-- day : Date -> Int | ||
-- day ld = | ||
-- native | ||
-- (ld | ||
-- |> Date.fromRataDie | ||
-- |> Date.day | ||
-- ) | ||
-- plusDays : Int -> Date -> Date | ||
-- plusDays dayCount ld = | ||
-- native | ||
-- (ld | ||
-- |> Date.fromRataDie | ||
-- |> Date.add Date.Days dayCount | ||
-- |> Date.toRataDie | ||
-- ) | ||
-- diffInDays : Date -> Date -> Int | ||
-- diffInDays ld1 ld2 = | ||
-- native | ||
-- (Date.diff | ||
-- Date.Days | ||
-- (ld1 |> Date.fromRataDie) | ||
-- (ld2 |> Date.fromRataDie) | ||
-- ) | ||
-- type alias Month = | ||
-- Native Date.Month | ||
-- lastDayOfMonth : Month -> Int -> Date | ||
-- lastDayOfMonth m y = | ||
-- native | ||
-- (Date.fromCalendarDate y m 1 | ||
-- |> Date.add Date.Months 1 | ||
-- |> Date.add Date.Days -1 | ||
-- |> Date.toRataDie | ||
-- ) | ||
-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Morphir.SDK.LocalDateTests exposing (..) | ||
|
||
import Expect | ||
import Test exposing (..) | ||
|
||
import Morphir.SDK.LocalDate | ||
|
||
ld = 1 | ||
|
||
{- | ||
import Time exposing (Month(..)) | ||
import Date exposing (Unit(..)) | ||
mathTests : Test | ||
mathTests = | ||
describe "date maths" | ||
[ test "add day" <| | ||
\_ -> | ||
(LocalDate.fromCalendarDate 2020 Jan 1) | ||
|> LocalDate.add Months 1 | ||
|> Expect.equal (LocalDate.fromCalendarDate 2020 Feb 1) | ||
] | ||
-} |