Introduced Dayjs as Server Plugin
This commit is contained in:
40
src/plugins/dayjs.ts
Normal file
40
src/plugins/dayjs.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import fp from "fastify-plugin"
|
||||||
|
import dayjs from "dayjs"
|
||||||
|
|
||||||
|
// 🧩 Plugins
|
||||||
|
import customParseFormat from "dayjs/plugin/customParseFormat.js";
|
||||||
|
import isBetween from "dayjs/plugin/isBetween.js";
|
||||||
|
import duration from "dayjs/plugin/duration.js";
|
||||||
|
import utc from "dayjs/plugin/utc"
|
||||||
|
import timezone from "dayjs/plugin/timezone"
|
||||||
|
import isSameOrAfter from "dayjs/plugin/isSameOrAfter"
|
||||||
|
import isSameOrBefore from "dayjs/plugin/isSameOrBefore"
|
||||||
|
import isoWeek from "dayjs/plugin/isoWeek"
|
||||||
|
import localizedFormat from "dayjs/plugin/localizedFormat"
|
||||||
|
|
||||||
|
// 🔧 Erweiterungen aktivieren
|
||||||
|
dayjs.extend(utc)
|
||||||
|
dayjs.extend(timezone)
|
||||||
|
dayjs.extend(isSameOrAfter)
|
||||||
|
dayjs.extend(isSameOrBefore)
|
||||||
|
dayjs.extend(isoWeek)
|
||||||
|
dayjs.extend(localizedFormat)
|
||||||
|
dayjs.extend(customParseFormat)
|
||||||
|
dayjs.extend(isBetween)
|
||||||
|
dayjs.extend(duration)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fastify Plugin: hängt dayjs an den Server an
|
||||||
|
*/
|
||||||
|
export default fp(async (server) => {
|
||||||
|
server.decorate("dayjs", dayjs)
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Typ-Erweiterung für TypeScript
|
||||||
|
*/
|
||||||
|
declare module "fastify" {
|
||||||
|
interface FastifyInstance {
|
||||||
|
dayjs: typeof dayjs
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user