Skip to content

Commit

Permalink
test(Locale): add test of format times in each locale.
Browse files Browse the repository at this point in the history
fix(Format): isoMsecOffsetFormat now defaults to %:z format to include colon in string, which seems a more general solution.
See #29 for context.

style(Internal): removed some left over Debug.log.
  • Loading branch information
rluiten committed Jan 31, 2017
1 parent 6ab010e commit e6dd919
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 76 deletions.
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# Date Extra Function
# Date Extra Package

### Introduction
A collection of modules for working with dates and times.

Only major changes are listed here.
* 2016/04/3 4.0.0
* Changed the name space from `Date.` to `Date.Extra.` for all modules.
* 2016/05/13 5.0.1
* Update to Elm 0.17.
* 2016/05/23 6.0.0
* Changing name of floor and ceil to startOfTime an endOfTime respectively and
moved them into TimeUnit module.
An Elm language package for working with dates and times.

---
### WARNING v8.2.0 2017/01/31
* ### Changes the value of `Format.isoMsecOffsetFormat`
* It now usses the %:z format token for zone offset which means they
now include ":" this now appears to be a better choice as it is
moregenerally parsed by browsers see issue. https://github.com/rluiten/elm-date-extra/issues/29.
* ### Changes result of `Format.isoString`
* which uses `Format.isoMsecOffsetFormat`.
---

### History
Only major (and recent) changes are listed here.
* 2016/07/25 8.0.0
* Add new format codes to format output day of month with a language idiom suffix.
* In English eg for 2015/04/02 '%-@d' outputs '2nd', '%@e' outputs ' 2nd'
Expand Down
2 changes: 1 addition & 1 deletion elm-package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "8.1.2",
"version": "8.2.0",
"summary": "Date Extra library add/subtract/diff/format etc dates.",
"repository": "https://github.com/rluiten/elm-date-extra.git",
"license": "BSD3",
Expand Down
2 changes: 1 addition & 1 deletion src/Date/Extra/Format.elm
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ isoOffsetFormat = "%Y-%m-%dT%H:%M:%S%z"

{-| ISO Date time with milliseconds and timezone, 24hr. -}
isoMsecOffsetFormat : String
isoMsecOffsetFormat = "%Y-%m-%dT%H:%M:%S.%L%z"
isoMsecOffsetFormat = "%Y-%m-%dT%H:%M:%S.%L%:z"


{-| ISO Date. -}
Expand Down
2 changes: 1 addition & 1 deletion src/Date/Extra/I18n/I_fr_fr.elm
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ dayOfMonthWithSuffix pad day =
_ -> (toString day)
in
if pad then
padLeft 4 ' ' value
padLeft 3 ' ' value
else
value
2 changes: 1 addition & 1 deletion src/Date/Extra/I18n/I_ro_ro.elm
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ monthName month =
dayOfMonthWithSuffix : Bool -> Int -> String
dayOfMonthWithSuffix pad day =
case day of
_ -> (toString day)
_ -> toString day
20 changes: 10 additions & 10 deletions src/Date/Extra/Internal.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ import Date.Extra.Period as Period
hackDateAsUtc : Date -> Date
hackDateAsUtc date =
let
_ = Debug.log "(local date) fields"
( Date.year date
, Date.month date
, Date.day date
, Date.hour date
, Date.minute date
, Date.second date
, Date.millisecond date
)
-- _ = Debug.log "(local date) fields"
-- ( Date.year date
-- , Date.month date
-- , Date.day date
-- , Date.hour date
-- , Date.minute date
-- , Date.second date
-- , Date.millisecond date
-- )
offset = getTimezoneOffset date
oHours = offset // Core.ticksAnHour
oMinutes = (offset - (oHours * Core.ticksAnHour)) // Core.ticksAMinute
_ = Debug.log "hackDateAsUtc" (offset, oHours, oMinutes)
-- _ = Debug.log "hackDateAsUtc" (offset, oHours, oMinutes)
in
hackDateAsOffset offset date

Expand Down
2 changes: 1 addition & 1 deletion tests/Date/Extra/ConvertingTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ convertingDates =
[ test
"output is exactly the same as iso input v1"
(\() -> Expect.equal
(Ok "2016-03-22T17:30:00.000+0000")
(Ok "2016-03-22T17:30:00.000+00:00")
(Date.fromString "2016-03-22T17:30:00.000Z" |> Result.andThen (Ok << dateToISO))
)
, test
Expand Down
60 changes: 30 additions & 30 deletions tests/Date/Extra/DurationTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -381,129 +381,129 @@ runAddCase (inputDateStr, duration, addend, expectedDateStr) =
addCases =
[ ( "2015/06/10 11:43:55.213"
, Millisecond, 1
, "2015-06-10T11:43:55.214+1000"
, "2015-06-10T11:43:55.214+10:00"
)
, ( "2015/06/10 11:43:55.213"
, Second, 1
, "2015-06-10T11:43:56.213+1000"
, "2015-06-10T11:43:56.213+10:00"
)
, ( "2015/06/10 11:43:55.213"
, Minute, 1
, "2015-06-10T11:44:55.213+1000"
, "2015-06-10T11:44:55.213+10:00"
)
, ( "2015/06/10 11:43:55.213"
, Hour, 1
, "2015-06-10T12:43:55.213+1000"
, "2015-06-10T12:43:55.213+10:00"
)
, ( "2015/06/10 11:43:55.213"
, Day, 1
, "2015-06-11T11:43:55.213+1000"
, "2015-06-11T11:43:55.213+10:00"
)
, ( "2015/06/10 11:43:55.213"
, Week, 1
, "2015-06-17T11:43:55.213+1000"
, "2015-06-17T11:43:55.213+10:00"
)
, ( "2015/06/10 11:43:55.213"
, Month, 1
, "2015-07-10T11:43:55.213+1000"
, "2015-07-10T11:43:55.213+10:00"
)
, ( "2015/06/10 11:43:55.213"
, Year, 1
, "2016-06-10T11:43:55.213+1000"
, "2016-06-10T11:43:55.213+10:00"
)

, ( "2015/02/28"
, Day, 1
, "2015-03-01T00:00:00.000+1000"
, "2015-03-01T00:00:00.000+10:00"
)
, ( "2012/02/28"
, Day, 1
, "2012-02-29T00:00:00.000+1000"
, "2012-02-29T00:00:00.000+10:00"
)

, ( "2012/02/29"
, Day, -1
, "2012-02-28T00:00:00.000+1000"
, "2012-02-28T00:00:00.000+10:00"
)
, ( "2015/01/01"
, Day, -1
, "2014-12-31T00:00:00.000+1000"
, "2014-12-31T00:00:00.000+10:00"
)

, ( "2015/06/10"
, Month, 1
, "2015-07-10T00:00:00.000+1000"
, "2015-07-10T00:00:00.000+10:00"
)
, ( "2015/01/02"
, Month, 1
, "2015-02-02T00:00:00.000+1000"
, "2015-02-02T00:00:00.000+10:00"
)
, ( "2015/01/31"
, Month, 1
, "2015-02-28T00:00:00.000+1000"
, "2015-02-28T00:00:00.000+10:00"
)
, ( "2012/01/31"
, Month, 1
, "2012-02-29T00:00:00.000+1000"
, "2012-02-29T00:00:00.000+10:00"
)

, ( "2015/07/10"
, Month, -1
, "2015-06-10T00:00:00.000+1000"
, "2015-06-10T00:00:00.000+10:00"
)
, ( "2015/02/02"
, Month, -1
, "2015-01-02T00:00:00.000+1000"
, "2015-01-02T00:00:00.000+10:00"
)
, ( "2015/02/28"
, Month, -1
, "2015-01-28T00:00:00.000+1000"
, "2015-01-28T00:00:00.000+10:00"
)
, ( "2012/02/29"
, Month, -1
, "2012-01-29T00:00:00.000+1000"
, "2012-01-29T00:00:00.000+10:00"
)

, ( "2012/02/29"
, Month, 1
, "2012-03-29T00:00:00.000+1000"
, "2012-03-29T00:00:00.000+10:00"
)

, ( "2015/06/10"
, Month, 2
, "2015-08-10T00:00:00.000+1000"
, "2015-08-10T00:00:00.000+10:00"
)
, ( "2015/01/03"
, Month, 2
, "2015-03-03T00:00:00.000+1000"
, "2015-03-03T00:00:00.000+10:00"
)
, ( "2015/01/31"
, Month, 2
, "2015-03-31T00:00:00.000+1000"
, "2015-03-31T00:00:00.000+10:00"
)
, ( "2012/01/31"
, Month, 2
, "2012-03-31T00:00:00.000+1000"
, "2012-03-31T00:00:00.000+10:00"
)

, ( "2015/07/10"
, Month, -2
, "2015-05-10T00:00:00.000+1000"
, "2015-05-10T00:00:00.000+10:00"
)
, ( "2015/02/02"
, Month, -2
, "2014-12-02T00:00:00.000+1000"
, "2014-12-02T00:00:00.000+10:00"
)
, ( "2015/02/28"
, Month, -2
, "2014-12-28T00:00:00.000+1000"
, "2014-12-28T00:00:00.000+10:00"
)
, ( "2012/02/29"
, Month, -2
, "2011-12-29T00:00:00.000+1000"
, "2011-12-29T00:00:00.000+10:00"
)
, ( "2012/03/31"
, Month, -2
, "2012-01-31T00:00:00.000+1000"
, "2012-01-31T00:00:00.000+10:00"
)
]
98 changes: 78 additions & 20 deletions tests/Date/Extra/FormatTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,29 @@ import Time exposing (Time)
-- import Date.Config as Config
import Date.Extra.Core as Core
import Date.Extra.Format as Format
import Date.Extra.Config.Config_en_us as Config_en_us
import Date.Extra.Config.Config_en_au as Config_en_au
import Date.Extra.Config.Config_en_us as Config_en_us
import Date.Extra.Config.Config_en_gb as Config_en_gb
import Date.Extra.Config.Config_fr_fr as Config_fr_fr
import Date.Extra.Config.Config_fi_fi as Config_fi_fi
import Date.Extra.Config.Config_pl_pl as Config_pl_pl
import Date.Extra.Config.Config_ro_ro as Config_ro_ro
import Date.Extra.Config.Config_nl_nl as Config_nl_nl
import Date.Extra.Config.Config_pt_br as Config_pt_br
import Date.Extra.Config.Config_et_ee as Config_et_ee
import Date.Extra.Period as DPeriod exposing (Period (Hour))


en_au_config = Config_en_au.config
en_us_config = Config_en_us.config
config_en_au = Config_en_au.config
config_en_us = Config_en_us.config
config_en_gb = Config_en_gb.config
config_fr_fr = Config_fr_fr.config
config_fi_fi = Config_fi_fi.config
config_pl_pl = Config_pl_pl.config
config_ro_ro = Config_ro_ro.config
config_nl_nl = Config_nl_nl.config
config_pt_br = Config_pt_br.config
config_et_ee = Config_et_ee.config


tests : Test
Expand All @@ -31,6 +47,8 @@ tests =
List.map runFormatUtcTest formatUtcTestCases
, describe "formatOffset tests" <|
List.map runformatOffsetTest formatOffsetTestCases
, describe "configLanguage tests" <|
List.map runConfigLanguageTest formatConfigTestCases
]


Expand Down Expand Up @@ -78,10 +96,10 @@ runFormatTest (name, expected, formatStr, time) =
-- )
in
test name <|
\() ->
Expect.equal
expected
(Format.formatOffset Config_en_us.config -600 formatStr asDate)
\() ->
Expect.equal
expected
(Format.formatOffset Config_en_us.config -600 formatStr asDate)


formatTestCases =
Expand All @@ -96,21 +114,21 @@ formatTestCases =
, ("with milliseconds 2", "2014-08-12T18:53:51.116", "%Y-%m-%dT%H:%M:%S.%L", aTestTime)
, ("small year", "0448-09-09T22:39:28.884", "%Y-%m-%dT%H:%M:%S.%L", aTestTime3)

, ("Config_en_us date", "8/5/2014", en_us_config.format.date, aTestTime5)
, ("Config_en_us longDate", "Tuesday, August 05, 2014", en_us_config.format.longDate, aTestTime5)
, ("Config_en_us time", "5:53 AM", en_us_config.format.time, aTestTime5)
, ("Config_en_us longTime", "5:53:51 AM", en_us_config.format.longTime, aTestTime5)
, ("Config_en_us dateTime", "8/5/2014 5:53 AM", en_us_config.format.dateTime, aTestTime5)
, ("Config_en_us dateTime test PM", "8/4/2014 12:00 PM", en_us_config.format.dateTime, aTestTime6)
, ("Config_en_us dateTime test AM", "8/4/2014 12:00 AM", en_us_config.format.dateTime, aTestTime7)
, ("Config_en_us date", "8/5/2014", config_en_us.format.date, aTestTime5)
, ("Config_en_us longDate", "Tuesday, August 05, 2014", config_en_us.format.longDate, aTestTime5)
, ("Config_en_us time", "5:53 AM", config_en_us.format.time, aTestTime5)
, ("Config_en_us longTime", "5:53:51 AM", config_en_us.format.longTime, aTestTime5)
, ("Config_en_us dateTime", "8/5/2014 5:53 AM", config_en_us.format.dateTime, aTestTime5)
, ("Config_en_us dateTime test PM", "8/4/2014 12:00 PM", config_en_us.format.dateTime, aTestTime6)
, ("Config_en_us dateTime test AM", "8/4/2014 12:00 AM", config_en_us.format.dateTime, aTestTime7)

, ("Config_en_au date", "5/08/2014", en_au_config.format.date, aTestTime5)
, ("Config_en_au longDate", "Tuesday, 5 August 2014", en_au_config.format.longDate, aTestTime5)
, ("Config_en_au time", "5:53 AM", en_au_config.format.time, aTestTime5)
, ("Config_en_au longTime", "5:53:51 AM", en_au_config.format.longTime, aTestTime5)
, ("Config_en_au dateTime", "5/08/2014 5:53 AM", en_au_config.format.dateTime, aTestTime5)
, ("Config_en_au date", "5/08/2014", config_en_au.format.date, aTestTime5)
, ("Config_en_au longDate", "Tuesday, 5 August 2014", config_en_au.format.longDate, aTestTime5)
, ("Config_en_au time", "5:53 AM", config_en_au.format.time, aTestTime5)
, ("Config_en_au longTime", "5:53:51 AM", config_en_au.format.longTime, aTestTime5)
, ("Config_en_au dateTime", "5/08/2014 5:53 AM", config_en_au.format.dateTime, aTestTime5)

, ("Config_en_us date", "8/12/2014", en_us_config.format.date, aTestTime)
, ("Config_en_us date", "8/12/2014", config_en_us.format.date, aTestTime)

-- year rendered negative ? boggle :) disabled for not supporting at moment
--, ("small year", "0448-09-09T22:39:28.885", "%Y-%m-%dT%H:%M:%S.%L", aTestTime4)
Expand All @@ -124,6 +142,46 @@ formatTestCases =
]


runConfigLanguageTest (name, expected, config, formatStr, time) =
let
asDate = Core.fromTime time
in
test name <|
\() ->
Expect.equal
expected
(Format.formatOffset config -600 formatStr asDate)


{-
These tests are testing a few language field values and the day idiom function.
I currently believe several of the locales that dont pad the day idiom may be incorrect.
-}
dayDayIdiomMonth = "%A (%@e) %d %B %Y"
formatConfigTestCases =
[ ("Config_en_au format", "5/08/2014", config_en_au, config_en_au.format.date, aTestTime5)
, ("Config_en_au format idiom", "Tuesday ( 5th) 05 August 2014", config_en_au, dayDayIdiomMonth, aTestTime5)
, ("Config_en_us day idiom", "8/5/2014", config_en_us, config_en_us.format.date, aTestTime5)
, ("Config_en_us format idiom", "Tuesday ( 5th) 05 August 2014", config_en_us, dayDayIdiomMonth, aTestTime5)
, ("Config_en_gb day idiom", "5/08/2014", config_en_gb, config_en_gb.format.date, aTestTime5)
, ("Config_en_gb format idiom", "Tuesday ( 5th) 05 August 2014", config_en_gb, dayDayIdiomMonth, aTestTime5)
, ("Config_fr_fr day idiom", "5/08/2014", config_fr_fr, config_fr_fr.format.date, aTestTime5)
, ("Config_fr_fr format idiom", "Mardi ( 5) 05 Août 2014", config_fr_fr, dayDayIdiomMonth, aTestTime5)
, ("Config_fi_fi day idiom", "5.8.2014", config_fi_fi, config_fi_fi.format.date, aTestTime5)
, ("Config_fi_fi format idiom", "tiistai (5) 05 elokuuta 2014", config_fi_fi, dayDayIdiomMonth, aTestTime5)
, ("Config_pl_pl day idiom", "05.08.2014", config_pl_pl, config_pl_pl.format.date, aTestTime5)
, ("Config_pl_pl format idiom", "wtorek (5) 05 sierpień 2014", config_pl_pl, dayDayIdiomMonth, aTestTime5)
, ("Config_ro_ro day idiom", "05.08.2014", config_ro_ro, config_ro_ro.format.date, aTestTime5)
, ("Config_ro_ro format idiom", "Marți (5) 05 August 2014", config_ro_ro, dayDayIdiomMonth, aTestTime5)
, ("Config_nl_nl day idiom", "8/5/2014", config_nl_nl, config_nl_nl.format.date, aTestTime5)
, ("Config_nl_nl format idiom", "dinsdag (5) 05 augustus 2014", config_nl_nl, dayDayIdiomMonth, aTestTime5)
, ("Config_pt_br day idiom", "05/08/2014", config_pt_br, config_pt_br.format.date, aTestTime5)
, ("Config_pt_br format idiom", "Terça-feira ( 5) 05 Agosto 2014", config_pt_br, dayDayIdiomMonth, aTestTime5)
, ("Config_et_ee day idiom", "5. aug 2014. a", config_et_ee, config_et_ee.format.date, aTestTime5)
, ("Config_et_ee format idiom", "teisipäev (5.) 05 august 2014", config_et_ee, dayDayIdiomMonth, aTestTime5)
]


runFormatUtcTest (name, expected, formatStr, time) =
test name <|
\() ->
Expand Down

0 comments on commit e6dd919

Please sign in to comment.