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.1.1 to 1.1.2

90

datelib.ts

@@ -7,47 +7,91 @@ import * as moment from 'moment'

export const utcOffset = (): number =>
moment.parseZone(new Date()).utcOffset()
/**
* Creating a moment from a date object because we know that the format
* of our date is an iso 8601 string. This is much faster than having
* moment parse the string itself
*
* @param fmt
* @param val
*/
export const format = (fmt: string, val?: string) => val
? moment(new Date(val)).format(fmt)
: moment(new Date()).format(fmt)
// Creating a moment from a date object because we know that the format
// of our date is an iso 8601 string. This is much faster than having
// moment parse the string itself
export const toMoment = (val: string) => moment(new Date(val))
/**
* Standardized format for displaying time
*
* @param val
*/
export const formatTime = (val?: string) =>
format(TIME_FILTER_FORMAT, val)
export const format = (val: string, fmt: string) =>
moment(new Date(val)).format(fmt)
/**
* Standardized format for displaying date
*
* @param val
*/
export const formatDate = (val?: string) =>
format(DATE_FILTER_FORMAT, val)
export const formatSafe = (val: string|null|undefined, fmt: string) =>
typeof val === 'string' ? format(val, fmt) : ''
/**
* Format required for datetime-local html input type
*
* @param value
*/
export const formatDateForInput = (val: string) => {
const formatted = format(INPUT_DATE_FORMAT, val)
return formatted === 'Invalid date' ? val : formatted
}
export const formatTime = (val: string) =>
formatSafe(val, TIME_FILTER_FORMAT)
export const formatDate = (val: string) =>
formatSafe(val, DATE_FILTER_FORMAT)
/**
* Convert a number into minutes
*
* @param time
*/
export const formatMinutes = (time: number) =>
moment.duration(time, 'minute').asMinutes()
/**
* Compare one date string with another
*
* @param a
* @param b
*/
export const diff = (a: string, b: string) =>
moment(new Date(a)).diff(moment(new Date(b)))
/**
* Compare a datestring with the current time
*
* @param val
*/
export const diffNow = (val: string) =>
moment(new Date(val)).diff(moment(new Date()))
/**
* Convert a datestring into UTC
*
* @param val
*/
export const toUtc = (val: string) =>
moment.utc(new Date(val)).format()
/**
* Convert a datestring from UTC
*
* @param val
*/
export const fromUtc = (val: string) =>
moment(new Date(val)).local().format()
/**
* ISO string of current UTC datetime
*/
export const utcNow = () =>
moment.utc().toISOString()
/**
* Format required for datetime-local html input type
*
* @param value
* Get the utc offset
*/
export const formatDateForInput = (value: string) => {
const formatted = moment(new Date(value)).format(INPUT_DATE_FORMAT)
return formatted === 'Invalid date' ? value : formatted
}
export const utcOffset = (): number =>
moment.parseZone(new Date()).utcOffset()

@@ -7,8 +7,11 @@ "use strict";

exports.INPUT_DATE_FORMAT = 'YYYY-MM-DDTHH:mm';
exports.utcOffset = () => moment.parseZone(new Date()).utcOffset();
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) : '';
exports.formatTime = (val) => exports.formatSafe(val, exports.TIME_FILTER_FORMAT);
exports.formatDate = (val) => exports.formatSafe(val, exports.DATE_FILTER_FORMAT);
exports.format = (fmt, val) => val
? moment(new Date(val)).format(fmt)
: moment(new Date()).format(fmt);
exports.formatTime = (val) => exports.format(exports.TIME_FILTER_FORMAT, val);
exports.formatDate = (val) => exports.format(exports.DATE_FILTER_FORMAT, val);
exports.formatDateForInput = (val) => {
const formatted = exports.format(exports.INPUT_DATE_FORMAT, val);
return formatted === 'Invalid date' ? val : formatted;
};
exports.formatMinutes = (time) => moment.duration(time, 'minute').asMinutes();

@@ -20,6 +23,3 @@ exports.diff = (a, b) => moment(new Date(a)).diff(moment(new Date(b)));

exports.utcNow = () => moment.utc().toISOString();
exports.formatDateForInput = (value) => {
const formatted = moment(new Date(value)).format(exports.INPUT_DATE_FORMAT);
return formatted === 'Invalid date' ? value : formatted;
};
exports.utcOffset = () => moment.parseZone(new Date()).utcOffset();
//# sourceMappingURL=datelib.js.map
{
"name": "ts-datelib",
"version": "1.1.1",
"version": "1.1.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