mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
vue ui i18n: localized date/time strings: UNcomplicated by removing named months and using default JS toLocale***() methods and PYWB i18n locale; removed "cardinal suffix"; added smart hour range calculator
This commit is contained in:
parent
bb083e7f53
commit
c8f78cfedb
File diff suppressed because one or more lines are too long
@ -117,15 +117,15 @@ export class PywbSnapshot {
|
||||
}
|
||||
|
||||
getTimeDateFormatted() {
|
||||
return `${PywbI18N.instance.getMonth(this.month, 'short')} ${this.day}, ${this.year} at ${this.getTimeFormatted()}`;
|
||||
return new Date(this.year, this.month-1, this.day, this.hour, this.minute, this.second).toLocaleString(PywbI18N.getLocale()).toLowerCase();
|
||||
}
|
||||
|
||||
getDateFormatted() {
|
||||
return `${this.year}-${PywbI18N.instance.getMonth(this.month, 'short')}-${this.day}`;
|
||||
return new Date(this.year, this.month-1, this.day).toLocaleDateString(PywbI18N.getLocale()).toLowerCase();
|
||||
}
|
||||
|
||||
getTimeFormatted() {
|
||||
return (this.hour < 13 ? this.hour : (this.hour % 12)) + ":" + ((this.minute < 10 ? "0":"")+this.minute) + ":" + ((this.second < 10 ? "0":"")+this.second) + " " + (this.hour < 12 ? "am":"pm");
|
||||
return new Date(2000, 0, 1, this.hour, this.minute, this.second).toLocaleTimeString(PywbI18N.getLocale()).toLowerCase();
|
||||
}
|
||||
|
||||
getParentIds() {
|
||||
@ -462,7 +462,7 @@ PywbPeriod.prototype.findByFullId = function(fullId) {
|
||||
}
|
||||
return found;
|
||||
};
|
||||
PywbPeriod.prototype.getFullReadableId = function(hasDayCardinalSuffix) {
|
||||
PywbPeriod.prototype.getFullReadableId = function() {
|
||||
// remove "all-time" from parents (getParents(true) when printing readable id (of all parents and currrent
|
||||
switch (this.type) {
|
||||
case PywbPeriod.Type.all:
|
||||
@ -470,17 +470,21 @@ PywbPeriod.prototype.getFullReadableId = function(hasDayCardinalSuffix) {
|
||||
case PywbPeriod.Type.year:
|
||||
return this.id;
|
||||
case PywbPeriod.Type.month:
|
||||
return this.getReadableId(hasDayCardinalSuffix) + ' ' + this.parent.id;
|
||||
return this.getReadableId() + ' ' + this.parent.id;
|
||||
case PywbPeriod.Type.day: {
|
||||
return this.parent.getReadableId(hasDayCardinalSuffix) + ' ' + this.getReadableId(hasDayCardinalSuffix) + ', ' + this.parent.parent.id;
|
||||
return new Date(this.parent.parent.id, this.parent.id, this.getReadableId()).toLocaleDateString(PywbI18N.getLocale());
|
||||
}
|
||||
case PywbPeriod.Type.hour:
|
||||
return this.parent.parent.getReadableId(hasDayCardinalSuffix) + ' ' + this.parent.getReadableId(hasDayCardinalSuffix) + ', ' + this.parent.parent.parent.id + ' at ' + this.getReadableId(hasDayCardinalSuffix);
|
||||
const hourRange = this.getReadableId({hourRange: true});
|
||||
return this.parent.getFullReadableId() + ' ' + PywbI18N.instance._('from {hour1} to {hour2}', {
|
||||
hour1: hourRange[0],
|
||||
hour2: hourRange[1]
|
||||
});
|
||||
case PywbPeriod.Type.snapshot:
|
||||
return this.parent.parent.getReadableId(hasDayCardinalSuffix) + ' ' + this.parent.getReadableId(hasDayCardinalSuffix) + ', ' + this.parent.parent.parent.id + ' at ' + this.snapshot.getTimeFormatted();
|
||||
return this.snapshot.getTimeDateFormatted();
|
||||
}
|
||||
};
|
||||
PywbPeriod.prototype.getReadableId = function(hasDayCardinalSuffix) {
|
||||
PywbPeriod.prototype.getReadableId = function(opts={hourRange:null}) {
|
||||
switch (this.type) {
|
||||
case PywbPeriod.Type.all:
|
||||
return PywbI18N.instance._("All-time");
|
||||
@ -492,7 +496,7 @@ PywbPeriod.prototype.getReadableId = function(hasDayCardinalSuffix) {
|
||||
let suffix = "";
|
||||
// DISABLING cardinal suffix for now, as it is complicated to replicate in multiple locales with 1 simple function
|
||||
// TODO: add cardinal suffix handling later IF REQUESTED!
|
||||
// if (hasDayCardinalSuffix) {
|
||||
// if (cardinalSuffix) {
|
||||
// const singleDigit = this.id % 10;
|
||||
// const isTens = Math.floor(this.id / 10) === 1;
|
||||
// const suffixes = {1:"st", 2:"nd",3:"rd"};
|
||||
@ -501,8 +505,12 @@ PywbPeriod.prototype.getReadableId = function(hasDayCardinalSuffix) {
|
||||
return this.id + suffix;
|
||||
}
|
||||
case PywbPeriod.Type.hour:
|
||||
// REMOVING 12-hour 'am-pm' time format as it is US-EN specific; replace with 24-hour time (TODO: add locale-sensitive time-format IF REQUESTED)
|
||||
return ({1:"0:00", 2: "3:00", 3: "6:00", 4: "9:00", 5: "12:00", 6: "15:00", 7: "18:00", 8: "21:00"})[this.id];
|
||||
// use browser's locale setting to get time string and remove seconds, and lower-case it (in case AM-PM)
|
||||
const hours = [0, 3, 6, 9, 12, 15, 18, 21].map(hour => new Date(2000, 0, 1, hour, 0, 0).toLocaleTimeString(PywbI18N.getLocale()).replace(/^(\d{1,2}:\d\d):\d\d/, (m, m1)=> m1).toLowerCase());
|
||||
if (opts.hourRange) {
|
||||
return [hours[this.id-1], hours[this.id % hours.length]];
|
||||
}
|
||||
return hours[this.id-1];
|
||||
//return ({1:'midnight', 2: '6 am', 3: 'noon', 4: '6 pm'})[this.id];
|
||||
//return (this.id < 13 ? this.id : this.id % 12) + ' ' + (this.id < 12 ? 'am':'pm');
|
||||
case PywbPeriod.Type.snapshot:
|
||||
|
Loading…
x
Reference in New Issue
Block a user