New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ts-datelib

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-datelib - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

23

datelib.ts

@@ -5,2 +5,3 @@ import * as moment from 'moment'

export const TIME_FILTER_FORMAT: string = 'HH:mm'
export const INPUT_DATE_FORMAT: string = 'YYYY-MM-DDTHH:mm'

@@ -13,8 +14,8 @@ export const utcOffset = (): number =>

// moment parse the string itself
const toMoment = (val: string) => moment(new Date(val))
export const toMoment = (val: string) => moment(new Date(val))
export const format = (val: string, fmt: string) =>
toMoment(val).format(fmt)
moment(new Date(val)).format(fmt)
export const formatSafe = (val: string | null | undefined, fmt: string) =>
export const formatSafe = (val: string|null|undefined, fmt: string) =>
typeof val === 'string' ? format(val, fmt) : ''

@@ -32,6 +33,6 @@

export const diff = (a: string, b: string) =>
toMoment(a).diff(toMoment(b))
moment(new Date(a)).diff(moment(new Date(b)))
export const diffNow = (val: string) =>
toMoment(val).diff(moment(new Date()))
moment(new Date(val)).diff(moment(new Date()))

@@ -42,2 +43,12 @@ export const toUtc = (val: string) =>

export const fromUtc = (val: string) =>
moment(new Date(val)).local().format()
moment(new Date(val)).local().format()
/**
* Format required for datetime-local html input type
*
* @param value
*/
export const formatDateForInput = (value: string) => {
const formatted = moment(new Date(value)).format(INPUT_DATE_FORMAT)
return formatted === 'Invalid date' ? value : formatted
}

@@ -6,5 +6,6 @@ "use strict";

exports.TIME_FILTER_FORMAT = 'HH:mm';
exports.INPUT_DATE_FORMAT = 'YYYY-MM-DDTHH:mm';
exports.utcOffset = () => moment.parseZone(new Date()).utcOffset();
const toMoment = (val) => moment(new Date(val));
exports.format = (val, fmt) => toMoment(val).format(fmt);
exports.toMoment = (val) => moment(new Date(val));
exports.format = (val, fmt) => moment(new Date(val)).format(fmt);
exports.formatSafe = (val, fmt) => typeof val === 'string' ? exports.format(val, fmt) : '';

@@ -14,6 +15,10 @@ exports.formatTime = (val) => exports.formatSafe(val, exports.TIME_FILTER_FORMAT);

exports.formatMinutes = (time) => moment.duration(time, 'minute').asMinutes();
exports.diff = (a, b) => toMoment(a).diff(toMoment(b));
exports.diffNow = (val) => toMoment(val).diff(moment(new Date()));
exports.diff = (a, b) => moment(new Date(a)).diff(moment(new Date(b)));
exports.diffNow = (val) => moment(new Date(val)).diff(moment(new Date()));
exports.toUtc = (val) => moment.utc(new Date(val)).format();
exports.fromUtc = (val) => moment(new Date(val)).local().format();
exports.formatDateForInput = (value) => {
const formatted = moment(new Date(value)).format(exports.INPUT_DATE_FORMAT);
return formatted === 'Invalid date' ? value : formatted;
};
//# sourceMappingURL=datelib.js.map
{
"name": "ts-datelib",
"version": "1.0.1",
"version": "1.0.2",
"description": "Typescript date formatting",

@@ -5,0 +5,0 @@ "main": "dist/datelib.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc