Skip to content

Commit

Permalink
Introducing LocalDate
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengoldbaum committed Jul 9, 2020
1 parent eb46ff7 commit caeeac6
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 0 deletions.
126 changes: 126 additions & 0 deletions src/Morphir/SDK/LocalDate.elm
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
-- )
-}
24 changes: 24 additions & 0 deletions tests/Morphir/SDK/LocalDateTests.elm
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)
]
-}

0 comments on commit caeeac6

Please sign in to comment.