2026-03-18 16:33:29 +08:00
|
|
|
// 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);
|
|
|
|
|
|
2026-03-23 16:43:03 +08:00
|
|
|
// Format date as 'YYYY-MM-DD'
|
|
|
|
|
export const formatDate = (date) =>
|
|
|
|
|
`${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
|
|
|
|
|
|
|
|
|
|
// Get current time string 'HH:MM'
|
|
|
|
|
export const getCurrentTimeStr = () => new Date().toTimeString().slice(0, 5);
|
|
|
|
|
|
2026-03-18 16:33:29 +08:00
|
|
|
// 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',
|
|
|
|
|
};
|