@t0ri/dates
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -1,1 +0,1 @@ | ||
var t=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.date=new Date(t)};export default t; | ||
var e=function(){function e(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.date=new Date(e)}return Object.defineProperty(e.prototype,"year",{get:function(){return this.date.getFullYear()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"month",{get:function(){return["January","February","March","April","May","June","July","August","September","October","November","December"][this.date.getMonth()]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"monthShort",{get:function(){return["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"][this.date.getMonth()]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"weekday",{get:function(){return["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][this.date.getDay()]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"day",{get:function(){return this.date.getDate()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"hours",{get:function(){return this.date.getHours()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"minutes",{get:function(){return this.date.getMinutes()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"seconds",{get:function(){return this.date.getSeconds()},enumerable:!0,configurable:!0}),e.prototype.format=function(e){var t="";e&&""!==e||(e="M d, Y");for(var r=0;r<e.length;r++){var n=e[r];if(n.match(/[a-zA-Z]/))switch(n){case"y":t+=String(this.year).slice(-2);break;case"Y":t+=this.year;break;case"m":t+=this.monthShort;break;case"M":t+=this.month;break;case"d":t+=this.day;break;case"D":if(1===String(this.day).length){t=t+"0"+this.day;break}t+=this.day;break;case"h":t+=this.hours;break;case"H":if(1===String(this.hours).length){t=t+"0"+this.hours;break}t+=this.hours;break;case"i":t+=this.minutes;break;case"I":if(1===String(this.minutes).length){t=t+"0"+this.minutes;break}t+=this.minutes;break;case"s":t+=this.seconds;break;case"S":if(1===String(this.seconds).length){t=t+"0"+this.seconds;break}t+=this.seconds}else t+=n}return t},e.prototype.when=function(e){var t,r;return(e=e?new Date(e):new Date)>this.date?(t=Math.ceil((e-this.date)/864e5))>31?(r=t/30)>12?(r/12).toFixed(0)+" years ago":r.toFixed(0)+" months ago":t.toFixed(0)+" days ago":(t=Math.ceil((this.date-e)/864e5))>31?(r=t/30)>12?(r/12).toFixed(0)+" years from now":r.toFixed(0)+" months from now":t.toFixed(0)+" days from now"},e}();module.exports=e,console.log(new e("2/19/98").when()); |
@@ -1,4 +0,23 @@ | ||
export default class Deight { | ||
date: Date; | ||
declare class Deight { | ||
date: any; | ||
constructor(...args: any); | ||
get year(): any; | ||
get month(): string; | ||
get monthShort(): string; | ||
get weekday(): string; | ||
get day(): any; | ||
get hours(): any; | ||
get minutes(): any; | ||
get seconds(): any; | ||
/** | ||
* This method creates a formatted date & time string. | ||
* @param {string} input any string using key letters. | ||
* @returns {string} formatted date & time string. | ||
*/ | ||
format(mask?: string): string; | ||
/** | ||
* This method creates a timestamp for how long ago the Deight was. | ||
* @returns {string} timestamp | ||
*/ | ||
when(today?: any): string; | ||
} |
{ | ||
"name": "@t0ri/dates", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "![Travis (.com)](https://img.shields.io/travis/com/t0ri/dates?style=flat-square) ![Coveralls github](https://img.shields.io/coveralls/github/t0ri/dates?style=flat-square) ![GitHub repo size](https://img.shields.io/github/repo-size/t0ri/dates?style=flat-square)", | ||
@@ -5,0 +5,0 @@ "main": "umd/dates.js", |
@@ -11,2 +11,54 @@ # Deights Library | ||
date.date -> 1998-02-19T08:00:00.000Z | ||
``` | ||
``` | ||
## Get Deight Values | ||
### Year | ||
``` | ||
const date = new Deight('2/19/1998') | ||
date.year -> 1998 | ||
``` | ||
### Month | ||
``` | ||
const date = new Deight('2/19/1998') | ||
date.month -> 'February' | ||
``` | ||
### Day | ||
``` | ||
const date = new Deight('2/19/1998') | ||
date.month -> 'February' | ||
``` | ||
### Hours | ||
``` | ||
const date = new Deight('2/19/1998 13:15:30') | ||
date.hours -> 13 | ||
``` | ||
### Minutes | ||
``` | ||
const date = new Deight('2/19/1998 13:15:30') | ||
date.minutes -> 15 | ||
``` | ||
### Seconds | ||
``` | ||
const date = new Deight('2/19/1998 13:15:30') | ||
date.seconds -> 30 | ||
``` | ||
## Format Mask | ||
Deight objects can return their date and time formatted with many options. | ||
``` | ||
const date = new Deight('2/19/1998 13:15:30') | ||
date.format('M d, Y') -> 'February 19, 1998' | ||
``` | ||
Format Key | ||
'Y' -> 2019 | ||
'y' -> 19 | ||
'M' -> July | ||
'm' -> Jul | ||
'D' -> 01 | ||
'd' -> 1 | ||
'H' -> 05 | ||
'h' -> 5 | ||
'I' -> 08 | ||
'i' -> 8 | ||
'S' -> 04 | ||
's' -> 4 |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).yourModule=t()}(this,(function(){"use strict";return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.date=new Date(e)}})); | ||
!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";var e=function(){function e(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.date=new Date(e)}return Object.defineProperty(e.prototype,"year",{get:function(){return this.date.getFullYear()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"month",{get:function(){return["January","February","March","April","May","June","July","August","September","October","November","December"][this.date.getMonth()]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"monthShort",{get:function(){return["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"][this.date.getMonth()]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"weekday",{get:function(){return["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][this.date.getDay()]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"day",{get:function(){return this.date.getDate()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"hours",{get:function(){return this.date.getHours()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"minutes",{get:function(){return this.date.getMinutes()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"seconds",{get:function(){return this.date.getSeconds()},enumerable:!0,configurable:!0}),e.prototype.format=function(e){var t="";e&&""!==e||(e="M d, Y");for(var r=0;r<e.length;r++){var n=e[r];if(n.match(/[a-zA-Z]/))switch(n){case"y":t+=String(this.year).slice(-2);break;case"Y":t+=this.year;break;case"m":t+=this.monthShort;break;case"M":t+=this.month;break;case"d":t+=this.day;break;case"D":if(1===String(this.day).length){t=t+"0"+this.day;break}t+=this.day;break;case"h":t+=this.hours;break;case"H":if(1===String(this.hours).length){t=t+"0"+this.hours;break}t+=this.hours;break;case"i":t+=this.minutes;break;case"I":if(1===String(this.minutes).length){t=t+"0"+this.minutes;break}t+=this.minutes;break;case"s":t+=this.seconds;break;case"S":if(1===String(this.seconds).length){t=t+"0"+this.seconds;break}t+=this.seconds}else t+=n}return t},e.prototype.when=function(e){var t,r;return(e=e?new Date(e):new Date)>this.date?(t=Math.ceil((e-this.date)/864e5))>31?(r=t/30)>12?(r/12).toFixed(0)+" years ago":r.toFixed(0)+" months ago":t.toFixed(0)+" days ago":(t=Math.ceil((this.date-e)/864e5))>31?(r=t/30)>12?(r/12).toFixed(0)+" years from now":r.toFixed(0)+" months from now":t.toFixed(0)+" days from now"},e}();module.exports=e,console.log(new e("2/19/98").when())})); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
8341
44
63
0