Files
accountbook/frontend/lib/utils.js
T

29 lines
865 B
JavaScript
Raw Normal View History

// Date utilities
export const getMonthStr = (date) =>
`${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`;
export const formatMonth = (date) =>
`${date.getFullYear()}${date.getMonth() + 1}月`;
export const formatMoney = (num) => (num || 0).toFixed(2);
// Parse date-time string 'YYYY-MM-DD HH:MM' into date and time parts
export const parseDateTime = (dateTimeStr) => {
if (!dateTimeStr) return { datePart: '', timePart: '00:00' };
const [datePart, timePart] = dateTimeStr.split(' ');
return { datePart, timePart: timePart || '00:00' };
};
// Extract date part from 'YYYY-MM-DD HH:MM'
export const getDatePart = (dateTimeStr) => {
if (!dateTimeStr) return '';
return dateTimeStr.split(' ')[0];
};
// Transaction type constants
export const TRANSACTION_TYPES = {
EXPENSE: 'expense',
INCOME: 'income',
ALL: 'all',
};