@@ -4,6 +4,7 @@ import { ro } from "date-fns/locale";
44import { CalendarIcon , XCircle } from "lucide-react" ;
55import * as React from "react" ;
66import type { DateRange } from "react-day-picker" ;
7+ import { parse , isValid , format as formatISODate } from "date-fns" ;
78
89import { Button } from "@/components/ui/button" ;
910import { Calendar } from "@/components/ui/calendar" ;
@@ -21,12 +22,10 @@ function getIsDateRange(value: DateSelection): value is DateRange {
2122 return value && typeof value === "object" && ! Array . isArray ( value ) ;
2223}
2324
24- function parseAsDate ( timestamp : number | string | undefined ) : Date | undefined {
25- if ( ! timestamp ) return undefined ;
26- const numericTimestamp =
27- typeof timestamp === "string" ? Number ( timestamp ) : timestamp ;
28- const date = new Date ( numericTimestamp ) ;
29- return ! Number . isNaN ( date . getTime ( ) ) ? date : undefined ;
25+ function parseAsDate ( dateString : string | undefined ) : Date | undefined {
26+ if ( ! dateString ) return undefined ;
27+ const parsed = parse ( dateString , "yyyy-MM-dd" , new Date ( ) ) ;
28+ return isValid ( parsed ) ? parsed : undefined ;
3029}
3130
3231function parseColumnFilterValue ( value : unknown ) {
@@ -36,14 +35,11 @@ function parseColumnFilterValue(value: unknown) {
3635
3736 if ( Array . isArray ( value ) ) {
3837 return value . map ( ( item ) => {
39- if ( typeof item === "number" || typeof item === "string" ) {
40- return item ;
41- }
42- return undefined ;
38+ return typeof item === "string" ? item : undefined ;
4339 } ) ;
4440 }
4541
46- if ( typeof value === "string" || typeof value === "number" ) {
42+ if ( typeof value === "string" ) {
4743 return [ value ] ;
4844 }
4945
@@ -89,11 +85,13 @@ export function DataTableDateFilter<TData>({
8985 }
9086
9187 if ( multiple && ! ( "getTime" in date ) ) {
92- const from = date . from ?. getTime ( ) ;
93- const to = date . to ?. getTime ( ) ;
88+ const from = date . from
89+ ? formatISODate ( date . from , "yyyy-MM-dd" )
90+ : undefined ;
91+ const to = date . to ? formatISODate ( date . to , "yyyy-MM-dd" ) : undefined ;
9492 column . setFilterValue ( from || to ? [ from , to ] : undefined ) ;
9593 } else if ( ! multiple && "getTime" in date ) {
96- column . setFilterValue ( date . getTime ( ) ) ;
94+ column . setFilterValue ( formatISODate ( date , "yyyy-MM-dd" ) ) ;
9795 }
9896 } ,
9997 [ column , multiple ]
@@ -179,7 +177,7 @@ export function DataTableDateFilter<TData>({
179177 { hasValue ? (
180178 < div
181179 role = "button"
182- aria-label = { `Sterge ${ title } ` }
180+ aria-label = { `Șterge ${ title } ` }
183181 tabIndex = { 0 }
184182 onClick = { onReset }
185183 className = "rounded-sm opacity-70 transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
0 commit comments