-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable use of Intl.RTF #5
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import Globalize from "globalize"; | ||
import ZonedDateTime from "zoned-date-time"; | ||
// import Globalize from "globalize"; | ||
// import ZonedDateTime from "zoned-date-time"; | ||
|
||
const second = 1e3; | ||
const minute = 6e4; | ||
|
@@ -22,7 +22,8 @@ function defineGetter(obj, prop, get) { | |
} | ||
|
||
function startOf(date, unit) { | ||
date = date instanceof ZonedDateTime ? date.clone() : new Date(date.getTime()); | ||
// date = date instanceof ZonedDateTime ? date.clone() : new Date(date.getTime()); | ||
date = new Date(date.getTime()); | ||
switch (unit) { | ||
case "year": date.setMonth(0); | ||
// falls through | ||
|
@@ -39,9 +40,9 @@ function startOf(date, unit) { | |
return date; | ||
} | ||
|
||
export default class RelativeTime { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removing the export looks weird to me. |
||
class RelativeTime { | ||
constructor() { | ||
this.formatters = RelativeTime.initializeFormatters(...arguments); | ||
this.rtf = new Intl.RelativeTimeFormat(undefined); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may need to include the |
||
} | ||
|
||
format(date, {timeZoneData = null, unit = "best-fit"} = {}) { | ||
|
@@ -104,13 +105,13 @@ export default class RelativeTime { | |
} | ||
|
||
switch(unit) { | ||
case "year": return formatters.year(diff.years); | ||
case "month": return formatters.month(diff.months); | ||
case "year": return this.rtf.format(diff.years, unit); | ||
case "month": return this.rtf.format(diff.months, unit); | ||
// case "week": return formatters.week(diff.weeks); | ||
case "day": return formatters.day(diff.days); | ||
case "hour": return formatters.hour(diff.hours); | ||
case "minute": return formatters.minute(diff.minutes); | ||
default: return formatters.second(diff.seconds); | ||
case "day": return this.rtf.format(diff.days, unit); | ||
case "hour": return this.rtf.format(diff.hours, unit); | ||
case "minute": return this.rtf.format(diff.minutes, unit); | ||
default: return this.rtf.format(diff.seconds, unit); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool to see Now, I would like to see if we can abstract the i18n library. Can we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm open for different plug-n-play ideas too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default wrappers could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rxaviers - Would you want to take it over? I'm not sure how you'd like to manage the pluggable backend There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make relative-time v2 to support |
||
} | ||
} | ||
} | ||
|
@@ -137,26 +138,3 @@ RelativeTime.threshold = { | |
minute: 59, // at least 59 minutes before using hour. | ||
second: 59 // at least 59 seconds before using minute. | ||
}; | ||
|
||
// TODO: Remove redundancy. The only reason this code is that ugly is to get | ||
// supported by globalize-compiler (which reads the static formatters). | ||
RelativeTime.initializeFormatters = function(globalize) { | ||
if (globalize) { | ||
return { | ||
second: globalize.relativeTimeFormatter("second"), | ||
minute: globalize.relativeTimeFormatter("minute"), | ||
hour: globalize.relativeTimeFormatter("hour"), | ||
day: globalize.relativeTimeFormatter("day"), | ||
month: globalize.relativeTimeFormatter("month"), | ||
year: globalize.relativeTimeFormatter("year") | ||
}; | ||
} | ||
return { | ||
second: Globalize.relativeTimeFormatter("second"), | ||
minute: Globalize.relativeTimeFormatter("minute"), | ||
hour: Globalize.relativeTimeFormatter("hour"), | ||
day: Globalize.relativeTimeFormatter("day"), | ||
month: Globalize.relativeTimeFormatter("month"), | ||
year: Globalize.relativeTimeFormatter("year") | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still usages of ZonedDateTime in the code.