2020-05-14 09:30:32 +00:00
|
|
|
import { LocaleContext } from "@saleor/components/Locale";
|
2019-08-09 10:26:22 +00:00
|
|
|
import moment from "moment-timezone";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { useContext } from "react";
|
|
|
|
|
2020-09-03 10:25:16 +00:00
|
|
|
function useDateLocalize(): (date: string, format?: string) => string {
|
2019-10-16 15:18:29 +00:00
|
|
|
const { locale } = useContext(LocaleContext);
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2020-09-03 10:25:16 +00:00
|
|
|
return (date: string, format?: string) =>
|
2019-06-19 14:40:52 +00:00
|
|
|
moment(date)
|
|
|
|
.locale(locale)
|
2020-09-03 10:25:16 +00:00
|
|
|
.format(format || "ll");
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default useDateLocalize;
|