importação do dayjs como função

This commit is contained in:
Luiz Silva 2025-10-26 21:19:21 -03:00
parent 1d969c9b0d
commit 2cac8492fa
6 changed files with 99 additions and 65 deletions

View file

@ -1,32 +1,54 @@
// dayjsbr.ts
import dayjs from "dayjs"
import type dayjs from "dayjs"
import type duration from "dayjs/plugin/duration"
//import "dayjs/locale/pt-br"
import type isSameOrAfter from "dayjs/plugin/isSameOrAfter"
import type isSameOrBefore from "dayjs/plugin/isSameOrBefore"
import type minMax from "dayjs/plugin/minMax"
import type relativeTime from "dayjs/plugin/relativeTime"
import type timezone from "dayjs/plugin/timezone"
import type utc from "dayjs/plugin/utc"
import type weekOfYear from "dayjs/plugin/weekOfYear"
import duration from "dayjs/plugin/duration"
import isSameOrAfter from "dayjs/plugin/isSameOrAfter"
import isSameOrBefore from "dayjs/plugin/isSameOrBefore"
import minMax from "dayjs/plugin/minMax"
import relativeTime from "dayjs/plugin/relativeTime"
import timezone from "dayjs/plugin/timezone"
import utc from "dayjs/plugin/utc"
import weekOfYear from "dayjs/plugin/weekOfYear"
/**
*
* dayjsbr.ts
*import dayjs from "dayjs"
*import "dayjs/locale/pt-br"
*import duration from "dayjs/plugin/duration"
*import isSameOrAfter from "dayjs/plugin/isSameOrAfter"
*import isSameOrBefore from "dayjs/plugin/isSameOrBefore"
*import minMax from "dayjs/plugin/minMax"
*import relativeTime from "dayjs/plugin/relativeTime"
*import timezone from "dayjs/plugin/timezone"
*import utc from "dayjs/plugin/utc"
*import weekOfYear from "dayjs/plugin/weekOfYear"
// ordem dos extends (utc antes de timezone)
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(weekOfYear)
dayjs.extend(isSameOrBefore)
dayjs.extend(isSameOrAfter)
dayjs.extend(minMax)
dayjs.extend(relativeTime)
dayjs.extend(duration)
//dayjs.locale("pt-br")
*/
export const criarDayjsbr = (
edayjs: typeof dayjs,
op: {
duration: typeof duration
isSameOrAfter: typeof isSameOrAfter
isSameOrBefore: typeof isSameOrBefore
minMax: typeof minMax
relativeTime: typeof relativeTime
timezone: typeof timezone
utc: typeof utc
weekOfYear: typeof weekOfYear
},
) => {
edayjs.extend(op.utc)
edayjs.extend(op.timezone)
edayjs.extend(op.weekOfYear)
edayjs.extend(op.isSameOrBefore)
edayjs.extend(op.isSameOrAfter)
edayjs.extend(op.minMax)
edayjs.extend(op.relativeTime)
edayjs.extend(op.duration)
edayjs.locale("pt-br")
export const dayjsbr = dayjs
export default dayjsbr
// útil para tipagens em chamadas de add/subtract etc.
export type { ManipulateType } from "dayjs"
export { dayjs }
return edayjs
}