diff --git a/elm-package.json b/elm-package.json index dd15b52..77945b6 100644 --- a/elm-package.json +++ b/elm-package.json @@ -1,5 +1,5 @@ { - "version": "1.1.0", + "version": "1.2.0", "summary": "Date Extra library add/subtract/diff/format etc dates.", "repository": "https://github.com/rluiten/elm-date-extra.git", "license": "BSD3", diff --git a/src/Date/Core.elm b/src/Date/Core.elm index def4c62..bb8ec7e 100644 --- a/src/Date/Core.elm +++ b/src/Date/Core.elm @@ -1,6 +1,7 @@ module Date.Core ( monthToInt , daysInMonth + , monthList , daysInNextMonth , daysInPrevMonth , daysInMonthDate @@ -33,6 +34,7 @@ module Date.Core ## Info @docs monthToInt @docs daysInMonth +@docs monthList @docs daysInNextMonth @docs daysInPrevMonth @docs daysInMonthDate @@ -165,6 +167,24 @@ toTime = floor << Date.toTime +{-| List of months in order from Jan to Dec. -} +monthList : List Month +monthList = + [ Jan + , Feb + , Mar + , Apr + , May + , Jun + , Jul + , Aug + , Sep + , Oct + , Nov + , Dec + ] + + {-| Return days in month for year month. -} daysInMonth : Int -> Month -> Int daysInMonth year month = diff --git a/src/Date/Format.elm b/src/Date/Format.elm index 41387bd..29c9362 100644 --- a/src/Date/Format.elm +++ b/src/Date/Format.elm @@ -251,7 +251,11 @@ formatOffsetStr betweenHoursMinutes offset = ++ (padWith '0' minute) -mod12 h = h % 12 +mod12 h = + if h % 12 == 0 then + 12 + else + h % 12 padWith : Char -> a -> String diff --git a/tests/Date/FormatTests.elm b/tests/Date/FormatTests.elm index 4e3d1f8..73d890c 100644 --- a/tests/Date/FormatTests.elm +++ b/tests/Date/FormatTests.elm @@ -12,6 +12,7 @@ import Time exposing (Time) import Date.Core as Core import Date.Format as Format import Date.Config.Config_en_us as English +import Date.Period as DPeriod exposing (Period (Hour)) tests : Test @@ -30,6 +31,11 @@ Time : 1407833631116 is : 2014-08-12T18:53:51.116+10:00 is : 2014-08-12T04:53:51.116-04:00 +Time : 1407855231116 + is : 2014-08-12T14:53:51.116+00:00 + is : 2014-08-13T00:53:51.116+10:00 + + Using floor here to work around bug in Elm 0.16 on Windows that cant produce this as integer into the javascript source. @@ -37,6 +43,9 @@ that cant produce this as integer into the javascript source. aTestTime = floor 1407833631116.0 +aTestTime2 = floor 1407855231116.0 + + formatTest _ = suite "format tests" <| List.map runFormatTest formatTestCases @@ -56,7 +65,6 @@ formatTestCases = , ("with %% no space", " %12/08/2014", " %%%d/%m/%Y", aTestTime) , ("with milliseconds", "2014-08-12 (.116)", "%Y-%m-%d (.%L)", aTestTime) , ("with milliseconds", "2014-08-12T18:53:51.116", "%Y-%m-%dT%H:%M:%S.%L", aTestTime) - ] @@ -98,4 +106,12 @@ formatOffsetTestCases = , ( "get back expected date in utc -12:00", "2014-08-12T20:53:51.116+12:00" , "%Y-%m-%dT%H:%M:%S.%L%:z", aTestTime, -720 ) + , ( "12 hour time %I", "Wednesday, 13 August 2014 12:53:51 AM" + , "%A, %e %B %Y %I:%M:%S %p" + , aTestTime2, -600 + ) + , ( "12 hour time %l", "Wednesday, 13 August 2014 12:53:51 AM" + , "%A, %e %B %Y %l:%M:%S %p" + , aTestTime2, -600 + ) ]