File tree Expand file tree Collapse file tree
src/pat/filemanager/src/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,6 +15,24 @@ describe("formatDate", () => {
1515 it ( "formats a real date string" , ( ) => {
1616 expect ( formatDate ( PAST ) ) . not . toBe ( "" ) ;
1717 } ) ;
18+
19+ it ( "respects the document language (es)" , ( ) => {
20+ const originalLang = document . documentElement . lang ;
21+ document . documentElement . lang = "es" ;
22+ const formatted = formatDate ( PAST ) ;
23+ // "ene" is the short month in Spanish for January (January 1st, 2020)
24+ expect ( formatted ) . toContain ( "ene" ) ;
25+ document . documentElement . lang = originalLang ;
26+ } ) ;
27+
28+ it ( "respects the document language (en)" , ( ) => {
29+ const originalLang = document . documentElement . lang ;
30+ document . documentElement . lang = "en" ;
31+ const formatted = formatDate ( PAST ) ;
32+ // "Jan" is the short month in English for January
33+ expect ( formatted ) . toContain ( "Jan" ) ;
34+ document . documentElement . lang = originalLang ;
35+ } ) ;
1836} ) ;
1937
2038describe ( "formatSize" , ( ) => {
Original file line number Diff line number Diff line change @@ -10,10 +10,16 @@ function parseDate(value: unknown): Date | null {
1010 return Number . isNaN ( date . getTime ( ) ) ? null : date ;
1111}
1212
13+ /** Detect the current UI language from the <html> tag, normalized for Intl. */
14+ function getLang ( ) : string {
15+ if ( typeof document === "undefined" ) return "en" ;
16+ return ( document . documentElement . lang || "en" ) . replace ( "_" , "-" ) ;
17+ }
18+
1319export function formatDate ( value : unknown ) : string {
1420 const date = parseDate ( value ) ;
1521 if ( ! date ) return "" ;
16- return new Intl . DateTimeFormat ( undefined , {
22+ return new Intl . DateTimeFormat ( getLang ( ) , {
1723 year : "numeric" ,
1824 month : "short" ,
1925 day : "numeric" ,
You can’t perform that action at this time.
0 commit comments