react-timestamp
Advanced tools
Comparing version
@@ -1,1 +0,1 @@ | ||
var e=require("react");function t(){return t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a])}return e},t.apply(this,arguments)}var r=function(e,t){switch(e){case"second":case"minute":case"hour":case"day":case"week":case"month":case"year":return t+" "+e+(1==t?"":"s");case"d_ago":return t+" ago";case"in_d":return"in "+t;default:return e}},a=function(e){if(!e)return new Date;if("number"==typeof e||""+parseInt(e,10)==e){if(e=parseInt(e,10),isNaN(e))return null;e=new Date(1e3*e)}if(e=new Date(e),isNaN(e.getTime()))return null;var t=e.toJSON().split(/[:\-\+TZ\. ]/);for(var r in t)if(""!==t[r]&&isNaN(parseInt(t[r],10)))return null;return e},n=function(e,a){var n,u,o;void 0===a&&(a={}),(a=t({format:"full",includeDay:!1,twentyFourHour:!1},a)).twentyFourHour?(n=e.getHours().toString(),o=""):(n=e.getHours()%12==0?"12":(e.getHours()%12).toString(),o=e.getHours()>11?"pm":"am"),u=e.getMinutes()<10?"0"+e.getMinutes():""+e.getMinutes();var i=a.translate||r,s=[i("Jan"),i("Feb"),i("Mar"),i("Apr"),i("May"),i("Jun"),i("Jul"),i("Aug"),i("Sep"),i("Oct"),i("Nov"),i("Dec")],c=[i("Sunday"),i("Monday"),i("Tuesday"),i("Wednesday"),i("Thursday"),i("Friday"),i("Saturday")],l=a.includeDay?c[e.getDay()]+", ":"";switch(a.format){case"date":return""+l+e.getDate()+" "+s[e.getMonth()]+" "+e.getFullYear();case"time":return n+":"+u+o;case"json":return e.toJSON();default:return""+l+e.getDate()+" "+s[e.getMonth()]+" "+e.getFullYear()+", "+n+":"+u+o}};module.exports=function(t){var u=t.className,o=void 0===u?"":u,i=t.style,s=void 0===i?{}:i,c=t.component,l=t.date,d=t.relative,f=t.relativeTo,v=t.options,g=t.autoUpdate,m=e.useState(0),y=m[0],h=m[1];e.useEffect(function(){if(g){var e=setInterval(function(){return h(y+1)},6e4);return function(){return clearInterval(e)}}},[]);var p=c||"time",M=a(l);if(!M)return e.createElement(p,{},["Invalid date"]);var w=function(e,t){return Math.floor((t.getTime()-e.getTime())/1e3)}(M,a(f)||new Date),N=d&&Math.abs(w)<31536e3||f?function(e,t,a){void 0===t&&(t=!0),void 0===a&&(a=r);var n,u=e>=0,o=a||r;return e=Math.abs(e),t&&e<60?o(u?"just now":"soon"):(n=e<60?o("second",e):e<3600?o("minute",Math.round(e/60)):e<86400?o("hour",Math.round(e/3600)):e<604800?o("day",Math.round(e/86400)):e<2628e3?o("week",Math.round(e/604800)):e<31536e3?o("month",Math.round(e/2628e3)):o("year",Math.round(e/31536e3)),t?o(u?"d_ago":"in_d",n):n)}(w,!f,null==v?void 0:v.translate):n(M,v);return e.createElement(p,{className:o,style:s,timestamp:n(M,{format:"json"})},N)}; | ||
var e=require("react");function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},t.apply(this,arguments)}var r=function(e,t){switch(e){case"second":case"minute":case"hour":case"day":case"week":case"month":case"year":return t+" "+e+(1==t?"":"s");case"d_ago":return t+" ago";case"in_d":return"in "+t;default:return e}},n=function(e){if(!e)return new Date;if("number"==typeof e||""+parseInt(e,10)==e){if(e=parseInt(e,10),isNaN(e))return null;e=new Date(1e3*e)}if(e=new Date(e),isNaN(e.getTime()))return null;var t=e.toJSON().split(/[:\-\+TZ\. ]/);for(var r in t)if(""!==t[r]&&isNaN(parseInt(t[r],10)))return null;return e},a=function(e,n){var a,u,o;void 0===n&&(n={}),(n=t({format:"full",includeDay:!1,twentyFourHour:!1},n)).twentyFourHour?(a=e.getHours().toString(),o=""):(a=e.getHours()%12==0?"12":(e.getHours()%12).toString(),o=e.getHours()>11?"pm":"am"),u=e.getMinutes()<10?"0"+e.getMinutes():""+e.getMinutes();var i=n.translate||r,s=[i("Jan"),i("Feb"),i("Mar"),i("Apr"),i("May"),i("Jun"),i("Jul"),i("Aug"),i("Sep"),i("Oct"),i("Nov"),i("Dec")],c=[i("Sunday"),i("Monday"),i("Tuesday"),i("Wednesday"),i("Thursday"),i("Friday"),i("Saturday")],l=n.includeDay?c[e.getDay()]+", ":"";switch(n.format){case"date":return""+l+e.getDate()+" "+s[e.getMonth()]+" "+e.getFullYear();case"time":return a+":"+u+o;case"json":return e.toJSON();default:return""+l+e.getDate()+" "+s[e.getMonth()]+" "+e.getFullYear()+", "+a+":"+u+o}};module.exports=function(t){var u=t.className,o=void 0===u?"":u,i=t.style,s=void 0===i?{}:i,c=t.component,l=t.date,d=t.relative,f=t.relativeTo,g=t.options,v=t.autoUpdate,m=e.useState(0),y=m[0],h=m[1];e.useEffect(function(){if(v){var e=setInterval(function(){return h(y+1)},6e4);return function(){return clearInterval(e)}}},[]);var p=c||"time",M=n(l);if(!M)return e.createElement(p,{},["Invalid date"]);var w=function(e,t){return Math.floor((t.getTime()-e.getTime())/1e3)}(M,n(f)||new Date),N=d&&Math.abs(w)<31536e3||f?function(e,t,n){void 0===t&&(t=!0),void 0===n&&(n=r);var a,u=e>=0,o=n||r;return e=Math.abs(e),t&&e<60?o(u?"just now":"soon"):(a=e<60?o("second",e):e<3600?o("minute",Math.round(e/60)):e<86400?o("hour",Math.round(e/3600)):e<604800?o("day",Math.round(e/86400)):e<2628e3?o("week",Math.round(e/604800)):e<31536e3?o("month",Math.round(e/2628e3)):o("year",Math.round(e/31536e3)),t?o(u?"d_ago":"in_d",a):a)}(w,!f,null==g?void 0:g.translate):a(M,g);return e.createElement(p,{className:o,style:s,timestamp:a(M,{format:"json"})},N)}; |
@@ -17,3 +17,3 @@ export declare type FormatOptions = { | ||
*/ | ||
export declare const toDate: (date?: string | number | Date | undefined) => Date | null; | ||
export declare const toDate: (date?: Date | string | number) => Date | null; | ||
/** | ||
@@ -20,0 +20,0 @@ * Format a date to a nice string |
{ | ||
"name": "react-timestamp", | ||
"version": "5.3.0", | ||
"version": "6.0.0", | ||
"description": "A React component for displaying a datetime in the local timezone", | ||
@@ -8,3 +8,3 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"test": "alsatian ./tests/**/*.spec.ts*", | ||
"test": "jest", | ||
"prepublishOnly": "npm test && npm run build", | ||
@@ -25,3 +25,3 @@ "clean": "rimraf dist", | ||
"author": "Nathan Hoad <nathan@nathanhoad.net>", | ||
"license": "ISC", | ||
"license": "MIT", | ||
"bugs": { | ||
@@ -32,16 +32,20 @@ "url": "https://github.com/nathanhoad/react-timestamp/issues" | ||
"peerDependencies": { | ||
"react": "^16.9.0" | ||
"react": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^16.9.0", | ||
"@types/react-test-renderer": "^16.9.0", | ||
"alsatian": "^3.2.1", | ||
"@testing-library/jest-dom": "^5.16.5", | ||
"@testing-library/react": "^13.4.0", | ||
"@types/jest": "^29.1.2", | ||
"@types/react": "^18.0.21", | ||
"jest": "^29.2.0", | ||
"jest-environment-jsdom": "^29.2.0", | ||
"microbundle": "^0.15.0", | ||
"parcel": "^2.5.0", | ||
"react": "^16.9.0", | ||
"react-dom": "^16.9.0", | ||
"react-test-renderer": "^16.9.0", | ||
"process": "^0.11.10", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"rimraf": "^2.6.3", | ||
"rollup": "^1.7.3" | ||
"rollup": "^1.7.3", | ||
"ts-jest": "^29.0.3" | ||
} | ||
} |
7754
20.09%7
40%63
6.78%14
40%