playbook_ui 13.2.0.pre.alpha.PLAY986dateTimeRounding1150 → 13.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_kit/dateTime.ts +23 -54
- data/dist/playbook-rails.js +5 -5
- data/lib/playbook/version.rb +2 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c03b530a4b2b16b5dcf7ea348a4aa6a66db48f68359fed8469e47746c6fad2c
|
4
|
+
data.tar.gz: 5695a441ba55870888683da55c49814c94de842a952614d711325bfd1813fe35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb2dd83ad7e0030f750adb29cab24f33d979922ac9763e35de399c8df427053ae501e0b24a168116c6fccf876885bf7fc9e7e0356b94bae6ef7ccb14cf7bf45c
|
7
|
+
data.tar.gz: 51fa2673e72139fdfce189b16a2364430eb8518fb9480d5b8c203bd66956478654506a20e358fbd6e6de955c97270503ed69f92857fe51789ddc30595daff9b3
|
@@ -121,61 +121,30 @@ export const toIso = (newDate: Date | string): string => {
|
|
121
121
|
}
|
122
122
|
|
123
123
|
export const fromNow = (newDate: Date | string): string => {
|
124
|
-
const
|
125
|
-
const
|
126
|
-
|
127
|
-
const startDate = formattedDate.getTime()
|
128
|
-
const endDate = today.getTime()
|
124
|
+
const startDate = formatDate(newDate).getTime()
|
125
|
+
const endDate = new Date().getTime()
|
129
126
|
const elapsedTime = endDate - startDate
|
130
|
-
|
131
|
-
|
132
|
-
const
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
const
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
const TEN_AND_A_HALF_MONTHS = 27560000000
|
153
|
-
|
154
|
-
const MILLISECONDS_IN_A_MINUTE = 60000
|
155
|
-
const MILLISECONDS_IN_A_HOUR = 3600000
|
156
|
-
const MILLISECONDS_IN_A_DAY = 86400000
|
157
|
-
|
158
|
-
let elapsedTimeString = differenceInYears === 1 ? `${differenceInYears} year ago` : `${differenceInYears} years ago` // 320 days to 1+ year: "x year(s) ago"
|
159
|
-
|
160
|
-
// Inspiration: https://momentjs.com/docs/#/displaying/fromnow/
|
161
|
-
const intervals = [
|
162
|
-
{ min: 0, max: FOURTY_FIVE_SECONDS, value: "a few seconds ago" }, // 0-44.99 seconds
|
163
|
-
{ min: FOURTY_FIVE_SECONDS, max: NINETY_SECONDS, value: "a minute ago" }, // 45-89.99 seconds
|
164
|
-
{ min: NINETY_SECONDS, max: FOURTY_FIVE_MINUTES, value: `${Math.round(elapsedTime / MILLISECONDS_IN_A_MINUTE)} minutes ago` }, // 90s-44.49 minutes: "2 minutes ago ... 44 minutes ago"
|
165
|
-
{ min: FOURTY_FIVE_MINUTES, max: NINETY_MINUTES, value: "an hour ago" }, // 44.5-89.99 minutes
|
166
|
-
{ min: NINETY_MINUTES, max: TWENTY_TWO_HOURS, value: `${Math.round(elapsedTime / MILLISECONDS_IN_A_HOUR)} hours ago` }, // 90m-21.49 hours: "2 hours ago ... 21 hours ago"
|
167
|
-
{ min: TWENTY_TWO_HOURS, max: THIRTY_SIX_HOURS, value: "a day ago" }, // 21.5-35.99 hours
|
168
|
-
{ min: THIRTY_SIX_HOURS, max: TWENTY_SIX_DAYS, value: `${Math.round(elapsedTime / MILLISECONDS_IN_A_DAY)} days ago` }, // 36h-25.49 days: "2 days ago ... 25 days ago"
|
169
|
-
{ min: TWENTY_SIX_DAYS, max: FOURTY_FIVE_DAYS, value: "a month ago" }, // 25.5-44.99 days
|
170
|
-
{ min: FOURTY_FIVE_DAYS, max: TEN_AND_A_HALF_MONTHS, value: `${differenceInMonths()} months ago` }, // 45 days to 319 days: "2 months ago ... 10 months ago"
|
171
|
-
]
|
172
|
-
|
173
|
-
for (const interval of intervals) {
|
174
|
-
const { min, max, value } = interval
|
175
|
-
|
176
|
-
if (elapsedTime >= min && elapsedTime < max) {
|
177
|
-
elapsedTimeString = value
|
178
|
-
break
|
127
|
+
let elapsedTimeString = `${Math.round(elapsedTime / (365.25 * 24 * 60 * 60 * 1000))} years ago`; // 730+ days
|
128
|
+
|
129
|
+
const MILLISECONDS_IN_A_MONTH = 30.44 * 24 * 60 * 60 * 1000
|
130
|
+
|
131
|
+
const elapsedTimeData = [
|
132
|
+
{ min: 0, max: 44999, value: "a few seconds ago" }, // 0-44 seconds
|
133
|
+
{ min: 45000, max: 89999, value: "a minute ago" }, // 45-89 seconds
|
134
|
+
{ min: 90000, max: 2649999, value: `${Math.round(elapsedTime / 60000)} minutes ago`}, // 90s-44 minutes
|
135
|
+
{ min: 2650000, max: 7299999, value: "an hour ago" }, // 45-120 minutes
|
136
|
+
{ min: 7300000, max: 75699999, value: `${Math.round(elapsedTime / 3600000)} hours ago`}, // 2-21 hours
|
137
|
+
{ min: 75700000, max: 172899999, value: "a day ago" }, // 22-48 hours
|
138
|
+
{ min: 172900000, max: 2169999999, value: `${Math.round(elapsedTime / 86400000)} days ago`}, // 2-25 days
|
139
|
+
{ min: 2170000000, max: 5184999999, value: "a month ago"}, // 26-60 days
|
140
|
+
{ min: 5185000000, max: 27561699999, value: `${Math.round(elapsedTime / MILLISECONDS_IN_A_MONTH)} months ago`}, // 60-319 days
|
141
|
+
{ min: 27561700000, max: 63072999999, value: "a year ago"}, // 320-730 days
|
142
|
+
];
|
143
|
+
|
144
|
+
for (const timeDate of elapsedTimeData) {
|
145
|
+
if (elapsedTime >= timeDate.min && elapsedTime <= timeDate.max) {
|
146
|
+
elapsedTimeString = timeDate.value;
|
147
|
+
break;
|
179
148
|
}
|
180
149
|
}
|
181
150
|
|