fix(utils): extract localDateString to shared lib, replace .toISOString().slice() pattern across client
This commit is contained in:
parent
4b74a456d9
commit
c6708982a9
|
|
@ -1,7 +1,7 @@
|
|||
import React, { useMemo, useRef, useState } from 'react';
|
||||
import { AlertCircle, Pencil, Settings2 } from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
import { cn, fmt, fmtDate } from '@/lib/utils';
|
||||
import { cn, fmt, fmtDate, localDateString } from '@/lib/utils';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { StatusBadge } from './StatusBadge';
|
||||
|
|
@ -24,7 +24,7 @@ const ROW_STATUS_CLS = {
|
|||
function paymentDateForTrackerMonth(year, month, dueDay) {
|
||||
const now = new Date();
|
||||
if (year === now.getFullYear() && month === now.getMonth() + 1) {
|
||||
return fmtDate(new Date().toISOString().slice(0, 10));
|
||||
return localDateString();
|
||||
}
|
||||
|
||||
const daysInMonth = new Date(year, month, 0).getDate();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import React, { useState } from 'react';
|
|||
import { AlertCircle, ChevronDown, BellOff, SkipForward, CreditCard } from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
import { api } from '@/api.js';
|
||||
import { cn, fmt } from '@/lib/utils';
|
||||
import { cn, fmt, localDateString } from '@/lib/utils';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Collapsible, CollapsibleTrigger, CollapsibleContent } from '@/components/ui/collapsible';
|
||||
|
|
@ -16,7 +16,7 @@ import {
|
|||
function snoozeUntil(days) {
|
||||
const d = new Date();
|
||||
d.setDate(d.getDate() + days);
|
||||
return d.toISOString().slice(0, 10);
|
||||
return localDateString(d);
|
||||
}
|
||||
|
||||
function daysOverdueLabel(dueDate) {
|
||||
|
|
@ -142,7 +142,7 @@ function OverdueRow({ row, year, month, onPayNow, onRefresh }) {
|
|||
}
|
||||
|
||||
export default function OverdueCommandCenter({ rows, year, month, refresh, onPayNow }) {
|
||||
const todayStr = new Date().toISOString().slice(0, 10);
|
||||
const todayStr = localDateString();
|
||||
const [isOpen, setIsOpen] = useState(true);
|
||||
|
||||
const overdueRows = rows.filter(r =>
|
||||
|
|
|
|||
|
|
@ -15,8 +15,15 @@ export function fmtDate(dateStr) {
|
|||
return `${parseInt(m)}/${parseInt(d)}/${y}`;
|
||||
}
|
||||
|
||||
export function localDateString(date = new Date()) {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
|
||||
export function todayStr() {
|
||||
return new Date().toISOString().slice(0, 10);
|
||||
return localDateString();
|
||||
}
|
||||
|
||||
export function fmtUptime(seconds) {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import {
|
|||
X,
|
||||
} from 'lucide-react';
|
||||
import { api } from '@/api';
|
||||
import { cn, fmt, fmtDate } from '@/lib/utils';
|
||||
import { cn, fmt, fmtDate, localDateString } from '@/lib/utils';
|
||||
import { scheduleLabel } from '@/lib/billingSchedule';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
|
|
@ -125,7 +125,7 @@ function subscriptionNextDueDate(item, now = new Date()) {
|
|||
date = new Date(date.getFullYear(), date.getMonth() + step, dueDay);
|
||||
}
|
||||
}
|
||||
return date.toISOString().slice(0, 10);
|
||||
return localDateString(date);
|
||||
}
|
||||
|
||||
function decorateSavedSubscriptionBill(bill, categories) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import { useSearchPanelPreference } from '@/hooks/useSearchPanelPreference';
|
|||
import BillModal from '@/components/BillModal';
|
||||
import { makeBillDraft } from '@/lib/billDrafts';
|
||||
import { scheduleLabel, scheduleValue } from '@/lib/billingSchedule';
|
||||
import { cn, fmt } from '@/lib/utils';
|
||||
import { cn, fmt, localDateString } from '@/lib/utils';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import SearchFilterPanel from '@/components/SearchFilterPanel';
|
||||
|
|
@ -54,13 +54,6 @@ function fmtBalanceAge(isoStr) {
|
|||
return parseUtc(isoStr).toLocaleString(undefined, { month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' });
|
||||
}
|
||||
|
||||
function localDateString(date = new Date()) {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
|
||||
function settingEnabled(value, fallback = true) {
|
||||
if (value === undefined || value === null || value === '') return fallback;
|
||||
return value === true || value === 'true';
|
||||
|
|
|
|||
Loading…
Reference in New Issue