Skip to content

Commit a41148c

Browse files
author
Alex Fedoseev
authored
Merge pull request #7 from cknitt/feature/formatteddate
Implemented FormattedDate and FormattedTime.
2 parents a7a8985 + 20bf575 commit a41148c

File tree

3 files changed

+100
-5
lines changed

3 files changed

+100
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ yarn run build
2222
Then open some `*.html` from [`examples`](./examples) folder.
2323

2424
## Status
25-
Despite lots of unchecked the most hard work is done. I'll add bindings to the rest of the components once I need them. Fell free to help me out and submit PR.
25+
Despite lots of unchecked the most hard work is done. I'll add bindings to the rest of the components once I need them. Feel free to help me out and submit a PR.
2626

2727
- [x] addLocaleData
2828
- [x] intlShape
2929
- [x] injectIntl
3030
- [x] defineMessages
3131
- [x] IntlProvider
32-
- [ ] FormattedDate
32+
- [x] FormattedDate
3333
- [ ] FormattedDate (children-as-function)
34-
- [ ] FormattedTime
34+
- [x] FormattedTime
3535
- [ ] FormattedTime (children-as-function)
3636
- [ ] FormattedRelative
3737
- [ ] FormattedRelative (children-as-function)

examples/basic/Page.re

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ let make = (~locale, ~setLocale, _) => {
3232
<ReactIntl.DefinedMessage message=pageLocale##today />
3333
(" " |> ReasonReact.stringToElement)
3434
(
35-
Js.Date.now()
36-
|> Js.Date.fromFloat
35+
Js.Date.make()
3736
|> intl.formatDate
3837
|> ReasonReact.stringToElement
3938
)
39+
(" (intl.formatDate)" |> ReasonReact.stringToElement)
40+
<br />
41+
<ReactIntl.DefinedMessage message=pageLocale##today />
42+
(" " |> ReasonReact.stringToElement)
43+
<ReactIntl.FormattedDate value=(Js.Date.make()) />
44+
(" (FormattedDate)" |> ReasonReact.stringToElement)
4045
</div>
4146
)
4247
</ReactIntl.IntlInjector>

src/ReactIntl.re

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,96 @@ module DefinedMessage = {
621621
);
622622
};
623623

624+
module FormattedDate = {
625+
[@bs.module "react-intl"]
626+
external reactClass : ReasonReact.reactClass = "FormattedDate";
627+
let make =
628+
(
629+
~value: Js.Date.t,
630+
~format: option(string)=?,
631+
~localeMatcher: option(localeMatcher)=?,
632+
~formatMatcher: option(formatMatcher)=?,
633+
~timeZone: option(string)=?,
634+
~hour12: option(bool)=?,
635+
~weekday: option(textualFormat)=?,
636+
~era: option(textualFormat)=?,
637+
~year: option(numeralFormat)=?,
638+
~month: option(mixedFormat)=?,
639+
~day: option(numeralFormat)=?,
640+
~hour: option(numeralFormat)=?,
641+
~minute: option(numeralFormat)=?,
642+
~second: option(numeralFormat)=?,
643+
~timeZoneName: option(timeZoneName)=?,
644+
_,
645+
) =>
646+
ReasonReact.wrapJsForReason(
647+
~reactClass,
648+
~props={
649+
"value": value,
650+
"format": format |> Js.Nullable.fromOption,
651+
"localeMatcher": localeMatcher |> mapReasonLocaleMatcherToJs,
652+
"formatMatcher": formatMatcher |> mapReasonFormatMatcherToJs,
653+
"timeZone": timeZone |> Js.Nullable.fromOption,
654+
"hour12": hour12 |> mapOptBoolToJs,
655+
"weekday": weekday |> mapReasonTextualFormatToJs,
656+
"era": era |> mapReasonTextualFormatToJs,
657+
"year": year |> mapReasonNumeralFormatToJs,
658+
"month": month |> mapReasonMixedFormatToJs,
659+
"day": day |> mapReasonNumeralFormatToJs,
660+
"hour": hour |> mapReasonNumeralFormatToJs,
661+
"minute": minute |> mapReasonNumeralFormatToJs,
662+
"second": second |> mapReasonNumeralFormatToJs,
663+
"timeZoneName": timeZoneName |> mapReasonTimeZoneNameToJs,
664+
},
665+
[||],
666+
);
667+
};
668+
669+
module FormattedTime = {
670+
[@bs.module "react-intl"]
671+
external reactClass : ReasonReact.reactClass = "FormattedTime";
672+
let make =
673+
(
674+
~value: Js.Date.t,
675+
~format: option(string)=?,
676+
~localeMatcher: option(localeMatcher)=?,
677+
~formatMatcher: option(formatMatcher)=?,
678+
~timeZone: option(string)=?,
679+
~hour12: option(bool)=?,
680+
~weekday: option(textualFormat)=?,
681+
~era: option(textualFormat)=?,
682+
~year: option(numeralFormat)=?,
683+
~month: option(mixedFormat)=?,
684+
~day: option(numeralFormat)=?,
685+
~hour: option(numeralFormat)=?,
686+
~minute: option(numeralFormat)=?,
687+
~second: option(numeralFormat)=?,
688+
~timeZoneName: option(timeZoneName)=?,
689+
_,
690+
) =>
691+
ReasonReact.wrapJsForReason(
692+
~reactClass,
693+
~props={
694+
"value": value,
695+
"format": format |> Js.Nullable.fromOption,
696+
"localeMatcher": localeMatcher |> mapReasonLocaleMatcherToJs,
697+
"formatMatcher": formatMatcher |> mapReasonFormatMatcherToJs,
698+
"timeZone": timeZone |> Js.Nullable.fromOption,
699+
"hour12": hour12 |> mapOptBoolToJs,
700+
"weekday": weekday |> mapReasonTextualFormatToJs,
701+
"era": era |> mapReasonTextualFormatToJs,
702+
"year": year |> mapReasonNumeralFormatToJs,
703+
"month": month |> mapReasonMixedFormatToJs,
704+
"day": day |> mapReasonNumeralFormatToJs,
705+
"hour": hour |> mapReasonNumeralFormatToJs,
706+
"minute": minute |> mapReasonNumeralFormatToJs,
707+
"second": second |> mapReasonNumeralFormatToJs,
708+
"timeZoneName": timeZoneName |> mapReasonTimeZoneNameToJs,
709+
},
710+
[||],
711+
);
712+
};
713+
624714
/* Utils */
625715
let wrapUnicodeString = (input: string) => {j|$input|j};
626716

0 commit comments

Comments
 (0)