@hig/timestamp
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -52,2 +52,7 @@ import React, { Component } from 'react'; | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Timestamp.__proto__ || Object.getPrototypeOf(Timestamp)).call.apply(_ref, [this].concat(args))), _this), _this.humanizeTimestamp = function (timestamp) { | ||
var _this$props = _this.props, | ||
plural = _this$props.plural, | ||
timeDescriptors = _this$props.timeDescriptors, | ||
wordSpace = _this$props.wordSpace; | ||
var asSeconds = Date.parse(timestamp) / 1000; // TODO: handle future timestamps, or bad input? | ||
@@ -58,30 +63,34 @@ var nowAsSeconds = new Date().valueOf() / 1000; | ||
var distance = void 0; | ||
var timePassed = void 0; | ||
var ellapsedDescriptor = void 0; | ||
if (timeDifference < 60) { | ||
distance = Math.round(timeDifference); | ||
timePassed = distance + " " + pluralize("second", distance); | ||
ellapsedDescriptor = plural ? pluralize(timeDescriptors.second, distance) : timeDescriptors.second; | ||
} else if (timeDifference < 60 * 60) { | ||
// 1 hour | ||
distance = Math.round(timeDifference / 60); | ||
timePassed = distance + " " + pluralize("minute", distance); | ||
ellapsedDescriptor = plural ? pluralize(timeDescriptors.minute, distance) : timeDescriptors.minute; | ||
} else if (timeDifference < 60 * 60 * 24) { | ||
// 1 day | ||
distance = Math.round(timeDifference / (60 * 60)); | ||
timePassed = distance + " " + pluralize("hour", distance); | ||
ellapsedDescriptor = plural ? pluralize(timeDescriptors.hour, distance) : timeDescriptors.hour; | ||
} else if (timeDifference < 60 * 60 * 24 * 7) { | ||
// 1 week | ||
distance = Math.round(timeDifference / (60 * 60 * 24)); | ||
timePassed = distance + " " + pluralize("day", distance); | ||
ellapsedDescriptor = plural ? pluralize(timeDescriptors.day, distance) : timeDescriptors.day; | ||
} else if (timeDifference < 60 * 60 * 24 * (365 / 12)) { | ||
// 1 month | ||
distance = Math.round(timeDifference / (60 * 60 * 24 * 7)); | ||
timePassed = distance + " " + pluralize("week", distance); | ||
ellapsedDescriptor = plural ? pluralize(timeDescriptors.week, distance) : timeDescriptors.week; | ||
} else if (timeDifference < 60 * 60 * 24 * 30 * 12) { | ||
// # 1 year | ||
distance = Math.round(timeDifference / (60 * 60 * 24 * (365 / 12))); | ||
timePassed = distance + " " + pluralize("month", distance); | ||
ellapsedDescriptor = plural ? pluralize(timeDescriptors.month, distance) : timeDescriptors.month; | ||
} else { | ||
// More than 1 year | ||
distance = Math.round(timeDifference / (60 * 60 * 24 * 365)); | ||
ellapsedDescriptor = plural ? pluralize(timeDescriptors.year, distance) : timeDescriptors.year; | ||
} | ||
return timePassed + " ago"; | ||
return wordSpace ? distance + " " + ellapsedDescriptor + " " + timeDescriptors.ago : "" + distance + ellapsedDescriptor + timeDescriptors.ago; | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
@@ -124,2 +133,7 @@ } | ||
/** | ||
* If you want to pluralize the elapsed time unit | ||
* If "true" then it adds an "s" to the end of the time unit | ||
*/ | ||
plural: PropTypes.bool, | ||
/** | ||
* ISO date string | ||
@@ -129,6 +143,39 @@ */ | ||
/** | ||
* An object that allows for localization of all the time words used | ||
* By default the object property name is the same as the property value | ||
* Property names: second, minute, hour, day, week, month, year, ago | ||
*/ | ||
timeDescriptors: PropTypes.shape({ | ||
second: PropTypes.string, | ||
minute: PropTypes.string, | ||
hour: PropTypes.string, | ||
day: PropTypes.string, | ||
week: PropTypes.string, | ||
month: PropTypes.string, | ||
year: PropTypes.string, | ||
ago: PropTypes.string | ||
}), | ||
/** | ||
* Adds custom/overriding styles | ||
*/ | ||
stylesheet: PropTypes.func | ||
stylesheet: PropTypes.func, | ||
/** | ||
* If you want a space between words | ||
*/ | ||
wordSpace: PropTypes.bool | ||
}; | ||
Timestamp.defaultProps = { | ||
plural: true, | ||
timeDescriptors: { | ||
second: "second", | ||
minute: "minute", | ||
hour: "hour", | ||
day: "day", | ||
week: "week", | ||
month: "month", | ||
year: "year", | ||
ago: "ago" | ||
}, | ||
wordSpace: true | ||
}; | ||
Timestamp.__docgenInfo = { | ||
@@ -138,2 +185,13 @@ "description": "", | ||
"props": { | ||
"plural": { | ||
"type": { | ||
"name": "bool" | ||
}, | ||
"required": false, | ||
"description": "If you want to pluralize the elapsed time unit\nIf \"true\" then it adds an \"s\" to the end of the time unit", | ||
"defaultValue": { | ||
"value": "true", | ||
"computed": false | ||
} | ||
}, | ||
"timestamp": { | ||
@@ -146,2 +204,47 @@ "type": { | ||
}, | ||
"timeDescriptors": { | ||
"type": { | ||
"name": "shape", | ||
"value": { | ||
"second": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"minute": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"hour": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"day": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"week": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"month": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"year": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"ago": { | ||
"name": "string", | ||
"required": false | ||
} | ||
} | ||
}, | ||
"required": false, | ||
"description": "An object that allows for localization of all the time words used\nBy default the object property name is the same as the property value\nProperty names: second, minute, hour, day, week, month, year, ago", | ||
"defaultValue": { | ||
"value": "{\n second: \"second\",\n minute: \"minute\",\n hour: \"hour\",\n day: \"day\",\n week: \"week\",\n month: \"month\",\n year: \"year\",\n ago: \"ago\"\n}", | ||
"computed": false | ||
} | ||
}, | ||
"stylesheet": { | ||
@@ -153,2 +256,13 @@ "type": { | ||
"description": "Adds custom/overriding styles" | ||
}, | ||
"wordSpace": { | ||
"type": { | ||
"name": "bool" | ||
}, | ||
"required": false, | ||
"description": "If you want a space between words", | ||
"defaultValue": { | ||
"value": "true", | ||
"computed": false | ||
} | ||
} | ||
@@ -155,0 +269,0 @@ } |
@@ -59,2 +59,7 @@ 'use strict'; | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Timestamp.__proto__ || Object.getPrototypeOf(Timestamp)).call.apply(_ref, [this].concat(args))), _this), _this.humanizeTimestamp = function (timestamp) { | ||
var _this$props = _this.props, | ||
plural = _this$props.plural, | ||
timeDescriptors = _this$props.timeDescriptors, | ||
wordSpace = _this$props.wordSpace; | ||
var asSeconds = Date.parse(timestamp) / 1000; // TODO: handle future timestamps, or bad input? | ||
@@ -65,30 +70,34 @@ var nowAsSeconds = new Date().valueOf() / 1000; | ||
var distance = void 0; | ||
var timePassed = void 0; | ||
var ellapsedDescriptor = void 0; | ||
if (timeDifference < 60) { | ||
distance = Math.round(timeDifference); | ||
timePassed = distance + " " + pluralize("second", distance); | ||
ellapsedDescriptor = plural ? pluralize(timeDescriptors.second, distance) : timeDescriptors.second; | ||
} else if (timeDifference < 60 * 60) { | ||
// 1 hour | ||
distance = Math.round(timeDifference / 60); | ||
timePassed = distance + " " + pluralize("minute", distance); | ||
ellapsedDescriptor = plural ? pluralize(timeDescriptors.minute, distance) : timeDescriptors.minute; | ||
} else if (timeDifference < 60 * 60 * 24) { | ||
// 1 day | ||
distance = Math.round(timeDifference / (60 * 60)); | ||
timePassed = distance + " " + pluralize("hour", distance); | ||
ellapsedDescriptor = plural ? pluralize(timeDescriptors.hour, distance) : timeDescriptors.hour; | ||
} else if (timeDifference < 60 * 60 * 24 * 7) { | ||
// 1 week | ||
distance = Math.round(timeDifference / (60 * 60 * 24)); | ||
timePassed = distance + " " + pluralize("day", distance); | ||
ellapsedDescriptor = plural ? pluralize(timeDescriptors.day, distance) : timeDescriptors.day; | ||
} else if (timeDifference < 60 * 60 * 24 * (365 / 12)) { | ||
// 1 month | ||
distance = Math.round(timeDifference / (60 * 60 * 24 * 7)); | ||
timePassed = distance + " " + pluralize("week", distance); | ||
ellapsedDescriptor = plural ? pluralize(timeDescriptors.week, distance) : timeDescriptors.week; | ||
} else if (timeDifference < 60 * 60 * 24 * 30 * 12) { | ||
// # 1 year | ||
distance = Math.round(timeDifference / (60 * 60 * 24 * (365 / 12))); | ||
timePassed = distance + " " + pluralize("month", distance); | ||
ellapsedDescriptor = plural ? pluralize(timeDescriptors.month, distance) : timeDescriptors.month; | ||
} else { | ||
// More than 1 year | ||
distance = Math.round(timeDifference / (60 * 60 * 24 * 365)); | ||
ellapsedDescriptor = plural ? pluralize(timeDescriptors.year, distance) : timeDescriptors.year; | ||
} | ||
return timePassed + " ago"; | ||
return wordSpace ? distance + " " + ellapsedDescriptor + " " + timeDescriptors.ago : "" + distance + ellapsedDescriptor + timeDescriptors.ago; | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
@@ -131,2 +140,7 @@ } | ||
/** | ||
* If you want to pluralize the elapsed time unit | ||
* If "true" then it adds an "s" to the end of the time unit | ||
*/ | ||
plural: PropTypes.bool, | ||
/** | ||
* ISO date string | ||
@@ -136,6 +150,39 @@ */ | ||
/** | ||
* An object that allows for localization of all the time words used | ||
* By default the object property name is the same as the property value | ||
* Property names: second, minute, hour, day, week, month, year, ago | ||
*/ | ||
timeDescriptors: PropTypes.shape({ | ||
second: PropTypes.string, | ||
minute: PropTypes.string, | ||
hour: PropTypes.string, | ||
day: PropTypes.string, | ||
week: PropTypes.string, | ||
month: PropTypes.string, | ||
year: PropTypes.string, | ||
ago: PropTypes.string | ||
}), | ||
/** | ||
* Adds custom/overriding styles | ||
*/ | ||
stylesheet: PropTypes.func | ||
stylesheet: PropTypes.func, | ||
/** | ||
* If you want a space between words | ||
*/ | ||
wordSpace: PropTypes.bool | ||
}; | ||
Timestamp.defaultProps = { | ||
plural: true, | ||
timeDescriptors: { | ||
second: "second", | ||
minute: "minute", | ||
hour: "hour", | ||
day: "day", | ||
week: "week", | ||
month: "month", | ||
year: "year", | ||
ago: "ago" | ||
}, | ||
wordSpace: true | ||
}; | ||
Timestamp.__docgenInfo = { | ||
@@ -145,2 +192,13 @@ "description": "", | ||
"props": { | ||
"plural": { | ||
"type": { | ||
"name": "bool" | ||
}, | ||
"required": false, | ||
"description": "If you want to pluralize the elapsed time unit\nIf \"true\" then it adds an \"s\" to the end of the time unit", | ||
"defaultValue": { | ||
"value": "true", | ||
"computed": false | ||
} | ||
}, | ||
"timestamp": { | ||
@@ -153,2 +211,47 @@ "type": { | ||
}, | ||
"timeDescriptors": { | ||
"type": { | ||
"name": "shape", | ||
"value": { | ||
"second": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"minute": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"hour": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"day": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"week": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"month": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"year": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"ago": { | ||
"name": "string", | ||
"required": false | ||
} | ||
} | ||
}, | ||
"required": false, | ||
"description": "An object that allows for localization of all the time words used\nBy default the object property name is the same as the property value\nProperty names: second, minute, hour, day, week, month, year, ago", | ||
"defaultValue": { | ||
"value": "{\n second: \"second\",\n minute: \"minute\",\n hour: \"hour\",\n day: \"day\",\n week: \"week\",\n month: \"month\",\n year: \"year\",\n ago: \"ago\"\n}", | ||
"computed": false | ||
} | ||
}, | ||
"stylesheet": { | ||
@@ -160,2 +263,13 @@ "type": { | ||
"description": "Adds custom/overriding styles" | ||
}, | ||
"wordSpace": { | ||
"type": { | ||
"name": "bool" | ||
}, | ||
"required": false, | ||
"description": "If you want a space between words", | ||
"defaultValue": { | ||
"value": "true", | ||
"computed": false | ||
} | ||
} | ||
@@ -162,0 +276,0 @@ } |
@@ -0,1 +1,13 @@ | ||
# [@hig/timestamp-v1.2.0](https://github.com/Autodesk/hig/compare/@hig/timestamp@1.1.1...@hig/timestamp@1.2.0) (2020-08-18) | ||
### Bug Fixes | ||
* support for dates over a year old ([8dac1f6](https://github.com/Autodesk/hig/commit/8dac1f6)) | ||
### Features | ||
* allow for localization ([b80bcf2](https://github.com/Autodesk/hig/commit/b80bcf2)) | ||
# [@hig/timestamp-v1.1.1](https://github.com/Autodesk/hig/compare/@hig/timestamp@1.1.0...@hig/timestamp@1.1.1) (2020-05-12) | ||
@@ -2,0 +14,0 @@ |
{ | ||
"name": "@hig/timestamp", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "HIG Timestamp", | ||
@@ -34,3 +34,3 @@ "author": "Autodesk Inc.", | ||
"@hig/theme-context": "^3.0.0", | ||
"@hig/theme-data": "^2.16.0", | ||
"@hig/theme-data": "^2.17.0", | ||
"react": "^15.4.1 || ^16.3.2" | ||
@@ -37,0 +37,0 @@ }, |
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
24436
484