mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-03-14 15:09:59 -04:00
Use singular units so the library handles plurals.
This commit is contained in:
parent
13369c3809
commit
bfc4202d11
2 changed files with 19 additions and 19 deletions
|
@ -10,13 +10,13 @@ const getTopLevelTimeUnit = timeStamp => {
|
|||
const oneDayInMs = 1000 * 60 * 60 * 24;
|
||||
const oneHourInMs = 1000 * 60 * 60;
|
||||
const oneMinuteInMs = 1000 * 60;
|
||||
let unit = 'minutes';
|
||||
let unit = 'minute';
|
||||
let duration = diff / oneMinuteInMs;
|
||||
if (diff > oneDayInMs) {
|
||||
unit = 'days';
|
||||
unit = 'day';
|
||||
duration = diff / oneDayInMs;
|
||||
} else if (diff > oneHourInMs) {
|
||||
unit = 'hours';
|
||||
unit = 'hour';
|
||||
duration = diff / oneHourInMs;
|
||||
}
|
||||
return {
|
||||
|
@ -81,9 +81,9 @@ module.exports.formatTimeUntil = (futureTime, lang) => {
|
|||
// or, our remainder is smaller than the next level down.
|
||||
// e.g. if it is 1 hour 30 sec, we just show 1 hour or
|
||||
// if it is 1 day 45 min, we only show 1 day.
|
||||
if (timeInfo.unit === 'minutes' ||
|
||||
(timeInfo.unit === 'hours' && remainder < 1.0 / 60) ||
|
||||
(timeInfo.unit === 'days' && remainder < 1.0 / 24)) {
|
||||
if (timeInfo.unit === 'minute' ||
|
||||
(timeInfo.unit === 'hour' && remainder < 1.0 / 60) ||
|
||||
(timeInfo.unit === 'day' && remainder < 1.0 / 24)) {
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -93,12 +93,12 @@ module.exports.formatTimeUntil = (futureTime, lang) => {
|
|||
let remainingTime = 0;
|
||||
let unitsOfRemainingTime = '';
|
||||
|
||||
if (timeInfo.unit === 'hours') {
|
||||
if (timeInfo.unit === 'hour') {
|
||||
remainingTime = remainder * 60;
|
||||
unitsOfRemainingTime = 'minutes';
|
||||
} else if (timeInfo.unit === 'days') {
|
||||
unitsOfRemainingTime = 'minute';
|
||||
} else if (timeInfo.unit === 'day') {
|
||||
remainingTime = remainder * 24;
|
||||
unitsOfRemainingTime = 'hours';
|
||||
unitsOfRemainingTime = 'hour';
|
||||
}
|
||||
|
||||
const remainingParts = formatter.formatToParts(remainingTime, unitsOfRemainingTime);
|
||||
|
|
|
@ -33,7 +33,7 @@ describe('unit test lib/format-time.js', () => {
|
|||
|
||||
response = format.formatTimeUntil(twoMin, 'en');
|
||||
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(2, 'minutes');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(2, 'minute');
|
||||
|
||||
expect(response).toEqual('2 minutes');
|
||||
});
|
||||
|
@ -51,7 +51,7 @@ describe('unit test lib/format-time.js', () => {
|
|||
];
|
||||
mockFormatExpression.formatToParts.mockReturnValue(formatToPartsResponse);
|
||||
response = format.formatTimeUntil(twoHours, 'en');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(2, 'hours');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(2, 'hour');
|
||||
expect(response).toEqual('2 hours');
|
||||
});
|
||||
|
||||
|
@ -68,7 +68,7 @@ describe('unit test lib/format-time.js', () => {
|
|||
mockFormatExpression.formatToParts.mockReturnValue(formatToPartsResponse);
|
||||
|
||||
response = format.formatTimeUntil(twoDays, 'en');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(2, 'days');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(2, 'day');
|
||||
expect(response).toEqual('2 days');
|
||||
});
|
||||
|
||||
|
@ -95,8 +95,8 @@ describe('unit test lib/format-time.js', () => {
|
|||
.mockReturnValueOnce(formatToPartsResponseTwelveHours);
|
||||
|
||||
response = format.formatTimeUntil(twoDays, 'en');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(2.5, 'days');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(12, 'hours');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(2.5, 'day');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(12, 'hour');
|
||||
expect(response).toEqual('2 days 12 hours');
|
||||
});
|
||||
|
||||
|
@ -122,8 +122,8 @@ describe('unit test lib/format-time.js', () => {
|
|||
.mockReturnValueOnce(formatToPartsResponseTwo);
|
||||
|
||||
response = format.formatTimeUntil(twoDays, 'en');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(3.5, 'hours');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(30, 'minutes');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(3.5, 'hour');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(30, 'minute');
|
||||
expect(response).toEqual('3 hours 30 minutes');
|
||||
});
|
||||
|
||||
|
@ -142,7 +142,7 @@ describe('unit test lib/format-time.js', () => {
|
|||
.mockReturnValueOnce(formatToPartsResponse);
|
||||
|
||||
response = format.formatTimeUntil(aDayand10Min, 'en');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(1.007, 'days');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(1.007, 'day');
|
||||
expect(response).toEqual('1 days');
|
||||
});
|
||||
|
||||
|
@ -161,7 +161,7 @@ describe('unit test lib/format-time.js', () => {
|
|||
.mockReturnValueOnce(formatToPartsResponse);
|
||||
|
||||
response = format.formatTimeUntil(anHourAnd30Sec, 'en');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(1.008, 'hours');
|
||||
expect(mockFormatExpression.formatToParts).toHaveBeenCalledWith(1.008, 'hour');
|
||||
expect(response).toEqual('1 hours');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue