Skip to content
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

@damassi => Customize relative time formatting for moment #1306

Merged
merged 1 commit into from Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/schema/sale/__tests__/index.test.js
Expand Up @@ -431,19 +431,26 @@ describe("Sale type", () => {
},
"in progress",
],
[
{
live_start_at: moment().add(1, "minutes"),
registration_ends_at: moment().subtract(2, "days"),
},
"live in 1m",
],
[
{
live_start_at: moment().add(10, "minutes"),
registration_ends_at: moment().subtract(2, "days"),
},
"live in 10 minutes",
"live in 10m",
],
[
{
live_start_at: moment().add(20, "minutes"),
registration_ends_at: moment().subtract(2, "days"),
},
"live in 20 minutes",
"live in 20m",
],
[
{
Expand All @@ -464,44 +471,44 @@ describe("Sale type", () => {
live_start_at: moment().add(20, "days"),
registration_ends_at: moment().add(10, "days"),
},
"live in 20 days",
"live in 20d",
true, // used to fake registered bidder for this scenario
],
[
{
start_at: moment().add(1, "minutes"),
end_at: moment().add(10, "minutes"),
},
"ends in 10 minutes",
"ends in 10m",
],
[
{
start_at: moment().add(10, "minutes"),
end_at: moment().add(20, "minutes"),
},
"ends in 20 minutes",
"ends in 20m",
],
[
{
start_at: moment().add(1, "hours"),
end_at: moment().add(10, "hours"),
},
"ends in 10 hours",
"ends in 10h",
],
[
{
start_at: moment().add(2, "hours"),
end_at: moment().add(20, "hours"),
},
"ends in 20 hours",
"ends in 20h",
],
[
{ start_at: moment().add(1, "days"), end_at: moment().add(2, "days") },
"ends in 2 days",
"ends in 2d",
],
[
{ start_at: moment().add(1, "days"), end_at: moment().add(5, "days") },
"ends in 5 days",
"ends in 5d",
],
[
{
Expand Down
19 changes: 19 additions & 0 deletions src/schema/sale/display.ts
@@ -1,5 +1,24 @@
import moment from "moment"

moment.updateLocale("en", {
relativeTime: {
future: "in %s",
past: "%s ago",
s: "%ds",
ss: "%ds",
m: "%dm",
mm: "%dm",
h: "%dh",
hh: "%dh",
d: "%dd",
dd: "%dd",
M: "%dM",
MM: "%dM",
y: "%dY",
yy: "%dY",
},
})

export const isLiveOpen = sale => {
const liveStart = moment(sale.live_start_at)
return (
Expand Down
17 changes: 15 additions & 2 deletions yarn.lock
Expand Up @@ -2,6 +2,13 @@
# yarn lockfile v1


"@airbnb/node-memwatch@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@airbnb/node-memwatch/-/node-memwatch-1.0.2.tgz#a82e311ae27e05df4fb2cf8e4fbc75caaf7190a4"
dependencies:
bindings "^1.3.0"
nan "^2.9.2"

"@artsy/express-reloadable@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@artsy/express-reloadable/-/express-reloadable-1.3.0.tgz#93ba96f42f7c4ae65aa696ed45cc4d663e7ac88b"
Expand Down Expand Up @@ -1413,6 +1420,10 @@ binary-extensions@^1.0.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.11.0.tgz#46aa1751fb6a2f93ee5e689bb1087d4b14c6c205"

bindings@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.3.0.tgz#b346f6ecf6a95f5a815c5839fc7cdb22502f1ed7"

block-stream@*:
version "0.0.9"
resolved "https://registry.yarnpkg.com/block-stream/-/block-stream-0.0.9.tgz#13ebfe778a03205cfe03751481ebb4b3300c126a"
Expand Down Expand Up @@ -2068,8 +2079,6 @@ dd-trace@artsy/dd-trace-js#artsy:
semver "^5.5.0"
shimmer "^1.2.0"
url-parse "^1.4.3"
optionalDependencies:
"@airbnb/node-memwatch" "^1.0.2"

debug@2, debug@2.6.9, debug@^2, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9:
version "2.6.9"
Expand Down Expand Up @@ -4962,6 +4971,10 @@ nan@^2.3.0:
version "2.8.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.8.0.tgz#ed715f3fe9de02b57a5e6252d90a96675e1f085a"

nan@^2.9.2:
version "2.11.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.11.0.tgz#574e360e4d954ab16966ec102c0c049fd961a099"

nanomatch@^1.2.9:
version "1.2.9"
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.9.tgz#879f7150cb2dab7a471259066c104eee6e0fa7c2"
Expand Down