task-fixdatetime
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { format, isValid, parse, parseISO } from 'date-fns';
|
||||
import { isValid, parse, parseISO } from 'date-fns';
|
||||
import { formatDate } from '@/lib/date-format';
|
||||
import { formatNumber } from '@/lib/number-format';
|
||||
|
||||
function coerceDate(value: string | Date | null | undefined) {
|
||||
if (!value) {
|
||||
@@ -20,21 +22,14 @@ function coerceDate(value: string | Date | null | undefined) {
|
||||
|
||||
export function formatCrmDate(value: string | Date | null | undefined) {
|
||||
const date = coerceDate(value);
|
||||
return date ? format(date, 'dd/MM/yyyy') : '';
|
||||
return date ? formatDate(date) : '';
|
||||
}
|
||||
|
||||
export function formatCrmNumber(value: number | string | null | undefined, options?: Intl.NumberFormatOptions) {
|
||||
if (value === '' || value === null || value === undefined) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const parsed = typeof value === 'number' ? value : Number(String(value).replaceAll(',', ''));
|
||||
|
||||
if (Number.isNaN(parsed)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return new Intl.NumberFormat('en-US', options).format(parsed);
|
||||
export function formatCrmNumber(
|
||||
value: number | string | null | undefined,
|
||||
options?: Intl.NumberFormatOptions
|
||||
) {
|
||||
return formatNumber(value, options);
|
||||
}
|
||||
|
||||
export function sanitizeDecimalInput(value: string) {
|
||||
@@ -42,6 +37,5 @@ export function sanitizeDecimalInput(value: string) {
|
||||
const [head = '', ...tail] = normalized.split('.');
|
||||
const integerPart = head.replace(/(?!^)-/g, '');
|
||||
const decimalPart = tail.join('');
|
||||
|
||||
return decimalPart.length > 0 ? `${integerPart}.${decimalPart}` : integerPart;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user