saleor-dashboard/src/hooks/useDateLocalize.ts

15 lines
404 B
TypeScript
Raw Normal View History

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";
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
return (date: string, format?: string) =>
2019-06-19 14:40:52 +00:00
moment(date)
.locale(locale)
.format(format || "ll");
2019-06-19 14:40:52 +00:00
}
export default useDateLocalize;