@01-edu/shared 1.2.7 → 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/attrs-defs.js +2 -3
- package/package.json +1 -1
- package/toolbox.js +27 -9
package/attrs-defs.js
CHANGED
|
@@ -2622,7 +2622,7 @@ types.rankDefinitionName = Literal('', {
|
|
|
2622
2622
|
})
|
|
2623
2623
|
|
|
2624
2624
|
types.rankDefinition = TypeObject({
|
|
2625
|
-
label: 'Rank
|
|
2625
|
+
label: 'Rank requirements',
|
|
2626
2626
|
type: {
|
|
2627
2627
|
name: types.rankDefinitionName,
|
|
2628
2628
|
level: Literal(MAX_LEVEL, {
|
|
@@ -2630,7 +2630,6 @@ types.rankDefinition = TypeObject({
|
|
|
2630
2630
|
editable: true,
|
|
2631
2631
|
required: true,
|
|
2632
2632
|
// to put max level first in options - could also be [MAX_LEVEL, ...arrayOf(MAX_LEVEL -1, 0)]
|
|
2633
|
-
options: arrayOf(MAX_LEVEL, 0).reverse(),
|
|
2634
2633
|
check: (level, object) => {
|
|
2635
2634
|
checkIntegerInBetween(level, 0, MAX_LEVEL)
|
|
2636
2635
|
|
|
@@ -2651,7 +2650,7 @@ types.rankDefinition = TypeObject({
|
|
|
2651
2650
|
},
|
|
2652
2651
|
})
|
|
2653
2652
|
const sharedRanksDefinitions = {
|
|
2654
|
-
label: '
|
|
2653
|
+
label: 'Rank requirements',
|
|
2655
2654
|
instruction: 'List of ranks access conditions',
|
|
2656
2655
|
editable: true,
|
|
2657
2656
|
restrictive: true,
|
package/package.json
CHANGED
package/toolbox.js
CHANGED
|
@@ -166,19 +166,25 @@ export const formatedDurationColons = (seconds, { hoursOnly } = {}) => {
|
|
|
166
166
|
|
|
167
167
|
export const formatedMS = ms => formatedDuration(Math.round(ms / SEC))
|
|
168
168
|
export const timeUnits = [
|
|
169
|
-
{ label: 'y', size: 31536000 },
|
|
170
|
-
{ label: 'w', size: 604800 },
|
|
171
|
-
{ label: 'd', size: 86400 },
|
|
172
|
-
{ label: 'h', size: 3600 },
|
|
173
|
-
{ label: 'm', size: 60 },
|
|
174
|
-
{ label: 's', size: 1 },
|
|
169
|
+
{ label: 'y', fullLabel: 'year', size: 31536000 },
|
|
170
|
+
{ label: 'w', fullLabel: 'week', size: 604800 },
|
|
171
|
+
{ label: 'd', fullLabel: 'day', size: 86400 },
|
|
172
|
+
{ label: 'h', fullLabel: 'hour', size: 3600 },
|
|
173
|
+
{ label: 'm', fullLabel: 'minute', size: 60 },
|
|
174
|
+
{ label: 's', fullLabel: 'second', size: 1 },
|
|
175
175
|
]
|
|
176
|
-
export const formatedDuration = (
|
|
176
|
+
export const formatedDuration = (
|
|
177
|
+
seconds,
|
|
178
|
+
{ noSeconds, stopFirst, useFullLabel } = {},
|
|
179
|
+
) => {
|
|
177
180
|
const parts = []
|
|
178
|
-
for (const { label, size } of timeUnits) {
|
|
181
|
+
for (const { label, size, fullLabel } of timeUnits) {
|
|
179
182
|
const value = Math.floor(seconds / size)
|
|
180
183
|
if (value !== 0) {
|
|
181
|
-
parts.push(
|
|
184
|
+
parts.push(
|
|
185
|
+
`${value}${useFullLabel ? ` ${fullLabel}` : label}${value > 1 && useFullLabel ? 's' : ''}`,
|
|
186
|
+
)
|
|
187
|
+
if (stopFirst) return parts
|
|
182
188
|
seconds -= value * size
|
|
183
189
|
}
|
|
184
190
|
}
|
|
@@ -188,6 +194,18 @@ export const formatedDuration = (seconds, { noSeconds } = {}) => {
|
|
|
188
194
|
return parts.join(' ') || (noSeconds ? '0m' : '0s')
|
|
189
195
|
}
|
|
190
196
|
|
|
197
|
+
// Returns the difference between two dates in the following format: "3 months"
|
|
198
|
+
// Always returns the largest unit only
|
|
199
|
+
// If only one date is provided, it returns the difference between that date and now, the value is absolute
|
|
200
|
+
export const timeDiff = (date1, date2 = Date.now()) => {
|
|
201
|
+
if (!date1) return null
|
|
202
|
+
const diffMs = toDate(date1) - toDate(date2)
|
|
203
|
+
return formatedDuration(Math.floor(Math.abs(diffMs) / 1000), {
|
|
204
|
+
stopFirst: true,
|
|
205
|
+
useFullLabel: true,
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
|
|
191
209
|
const toDate = date => (date instanceof Date ? date : new Date(date))
|
|
192
210
|
export const toDateFormat = (d, isISO = true) => {
|
|
193
211
|
if (dateIsPermanent(d)) return '∞'
|