mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 06:59:09 +00:00
chore: cleanup utils
This commit is contained in:
@@ -1,21 +1,21 @@
|
|||||||
import { removePrependedZero } from '../viewerUtils.js';
|
import { removePrefixZeroes } from '../viewerUtils.js';
|
||||||
|
|
||||||
describe('removePrependedZero', () => {
|
describe('removePrependedZero', () => {
|
||||||
it('should remove "00:" from the start of the string', () => {
|
it('should remove "00:" from the start of the string', () => {
|
||||||
const timer = '00:10:10';
|
const timer = '00:10:10';
|
||||||
const result = removePrependedZero(timer);
|
const result = removePrefixZeroes(timer);
|
||||||
expect(result).toBe('10:10');
|
expect(result).toBe('10:10');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove "00:0:" from the start of the string', () => {
|
it('should remove "00:0:" from the start of the string', () => {
|
||||||
const timer = '00:01:10';
|
const timer = '00:01:10';
|
||||||
const result = removePrependedZero(timer);
|
const result = removePrefixZeroes(timer);
|
||||||
expect(result).toBe('1:10');
|
expect(result).toBe('1:10');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not modify the string if it does not start with "00:" or "00:0:"', () => {
|
it('should not modify the string if it does not start with "00:" or "00:0:"', () => {
|
||||||
const timer = '10:10:10';
|
const timer = '10:10:10';
|
||||||
const result = removePrependedZero(timer);
|
const result = removePrefixZeroes(timer);
|
||||||
expect(result).toBe(timer);
|
expect(result).toBe(timer);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export function getTimerByType(timerObject?: TimerTypeParams): number | null {
|
|||||||
* Receives a string such as 00:10:10 and removes the hours field if it is 00
|
* Receives a string such as 00:10:10 and removes the hours field if it is 00
|
||||||
* @param timer
|
* @param timer
|
||||||
*/
|
*/
|
||||||
export const removePrependedZero = (timer: string): string => {
|
export const removePrefixZeroes = (timer: string): string => {
|
||||||
if (timer.startsWith('00:0')) {
|
if (timer.startsWith('00:0')) {
|
||||||
return timer.slice(4);
|
return timer.slice(4);
|
||||||
}
|
}
|
||||||
@@ -37,3 +37,15 @@ export const removePrependedZero = (timer: string): string => {
|
|||||||
}
|
}
|
||||||
return timer;
|
return timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receives a string such as 00:10:00 and removes the seconds field if it is 00
|
||||||
|
* @param timer
|
||||||
|
*/
|
||||||
|
export const removePostZeroes = (timer: string): string => {
|
||||||
|
if (timer.endsWith(':00')) {
|
||||||
|
return timer.slice(0, -3);
|
||||||
|
}
|
||||||
|
|
||||||
|
return timer;
|
||||||
|
};
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { OverridableOptions } from '../../../common/models/View.types';
|
|||||||
import { formatTime } from '../../../common/utils/time';
|
import { formatTime } from '../../../common/utils/time';
|
||||||
import { isStringBoolean } from '../../../common/utils/viewUtils';
|
import { isStringBoolean } from '../../../common/utils/viewUtils';
|
||||||
import { useTranslation } from '../../../translation/TranslationProvider';
|
import { useTranslation } from '../../../translation/TranslationProvider';
|
||||||
import { getTimerByType, removePrependedZero } from '../common/viewerUtils';
|
import { getTimerByType, removePrefixZeroes } from '../common/viewerUtils';
|
||||||
|
|
||||||
import './MinimalTimer.scss';
|
import './MinimalTimer.scss';
|
||||||
|
|
||||||
@@ -159,7 +159,7 @@ export default function MinimalTimer(props: MinimalTimerProps) {
|
|||||||
showSeconds: !userOptions.hideTimerSeconds,
|
showSeconds: !userOptions.hideTimerSeconds,
|
||||||
format: 'hh:mm:ss a',
|
format: 'hh:mm:ss a',
|
||||||
});
|
});
|
||||||
display = removePrependedZero(display);
|
display = removePrefixZeroes(display);
|
||||||
if (display.length < 3) {
|
if (display.length < 3) {
|
||||||
display = `${display} ${getLocalizedString('common.minutes')}`;
|
display = `${display} ${getLocalizedString('common.minutes')}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { formatTime } from '../../../common/utils/time';
|
|||||||
import { isStringBoolean } from '../../../common/utils/viewUtils';
|
import { isStringBoolean } from '../../../common/utils/viewUtils';
|
||||||
import { useTranslation } from '../../../translation/TranslationProvider';
|
import { useTranslation } from '../../../translation/TranslationProvider';
|
||||||
import SuperscriptTime from '../common/superscript-time/SuperscriptTime';
|
import SuperscriptTime from '../common/superscript-time/SuperscriptTime';
|
||||||
import { getTimerByType, removePrependedZero } from '../common/viewerUtils';
|
import { getTimerByType, removePrefixZeroes } from '../common/viewerUtils';
|
||||||
|
|
||||||
import './Timer.scss';
|
import './Timer.scss';
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ export default function Timer(props: TimerProps) {
|
|||||||
showSeconds: !userOptions.hideTimerSeconds,
|
showSeconds: !userOptions.hideTimerSeconds,
|
||||||
format: 'hh:mm:ss a',
|
format: 'hh:mm:ss a',
|
||||||
});
|
});
|
||||||
display = removePrependedZero(display);
|
display = removePrefixZeroes(display);
|
||||||
if (display.length < 3) {
|
if (display.length < 3) {
|
||||||
display = `${display} ${getLocalizedString('common.minutes')}`;
|
display = `${display} ${getLocalizedString('common.minutes')}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user