@vicis/transform-date
TypeScript icon, indicating that this package has built-in type declarations

1.2.8 • Public • Published

Vicis

« Vicis Transform Date »

Vicis transformation plugin for date and time.

•• Vicis Documentation •• JavaScript Repository •• Deno Repository ••

npm downloads stars types build lgtm


💬 Usage

Require CommonJS.

const { Vicis } = require("vicis");
const { VicisTransformDate } = require("@vicis/transform-date");

Import as ECMAScript module.

import { Vicis } from "vicis";
import { VicisTransformDate } from "@vicis/transform-date";

Export separately as functions.

import {
  VicisTransformDate,
  toDateTime, toFormat, toHourMinSec, toISO,
  toISO8601, toRFC2822, toUnix, toYearMonthDay,
} from "@vicis/transform-date";

API

const serializer = Vicis.factory();

const model = { createdAt: new Date(), };
serializer.data(model);

Default serializer behaviour

console.log(serializer.getData());
{ "createdAt": "2020-06-15T12:30:45.290Z" }

toDateTime()

serializer.transform({
  createdAt: VicisTransformDate.toDateTime(),
});
{ "createdAt": "2020-06-15T12:30:45.000+00:00" }

toFormat()

const format = "YYYY-MM-DD HH:mm:ss";
serializer.transform({
  createdAt: VicisTransformDate.toFormat(format),
});
{ "createdAt": "2020-06-15 12:30:45" }

toHourMinSec()

serializer.transform({
  createdAt: VicisTransformDate.toHourMinSec(),
});
{ "createdAt": "12:30:45" }

toISO()

serializer.transform({
  createdAt: VicisTransformDate.toISO(),
});
{ "createdAt": "2020-06-15T12:30:45.000Z" }

toISO8601()

serializer.transform({
  createdAt: VicisTransformDate.toISO8601(),
});
{ "createdAt": "2020-06-15T12:30:45.000+00:00" }

toRFC2822()

serializer.transform({
  createdAt: VicisTransformDate.toRFC2822(),
});
{ "createdAt": "Mon, 15 Jun 2020 12:30:45 GMT" }

toUnix()

serializer.transform({
  createdAt: VicisTransformDate.toUnix(),
});
{ "createdAt": 1592224245000 }

toYearMonthDay()

serializer.transform({
  createdAt: VicisTransformDate.toYearMonthDay(),
});
{ "createdAt": "2020-06-15" }

toDateTime() with configuration

Priority: unixTimestamp, format, anything else for iso formatting.

const config = {
  format: undefined,
  keepLocalTime: true,
  keepOffset: true,
  unixTimestamp: false,
  utcOffset: undefined,
};
serializer.transform({
  createdAt: VicisTransformDate.toDateTime(config),
});
{ "createdAt": "2020-06-15T12:30:45.000+00:00" }

For test purposes only

If you are 💯 sure that you have correct dates and UTC offsets.

serializer.transform({
  createdAt: VicisTransformDate,
});
{ "createdAt": "2020-06-15T12:30:45.000+00:00" }

🗺️ My other projects

Full list here

Package Sidebar

Install

npm i @vicis/transform-date

Homepage

vicis.js.org

Weekly Downloads

41

Version

1.2.8

License

MIT

Unpacked Size

43.8 kB

Total Files

10

Last publish

Collaborators

  • r37r0m0d3l