File tree Expand file tree Collapse file tree
opensilex-front/front/src
components/annotations/list Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -142,9 +142,7 @@ export default class AnnotationList extends Vue {
142142 @Ref (" annotationModalForm" ) readonly annotationModalForm! : AnnotationModalForm ;
143143
144144 formatDate(dateStr : string ): string {
145- const localeString = new Date (dateStr ).toLocaleString ();
146-
147- return localeString .replace (/ \/ / g , ' -' );
145+ return this .$opensilex .$dateTimeFormatter .formatLocalFixedDateTime (dateStr );
148146 }
149147
150148 static getDefaultColumns() {
Original file line number Diff line number Diff line change @@ -95,6 +95,31 @@ export default class DateTimeFormatter {
9595 . format ( new Date ( dateTimeValue ) ) ;
9696 }
9797
98+ /**
99+ * Formats a date string into a local date and time string with the format `YYYY-MM-DD HH:mm:ss`.
100+ * The output uses the local timezone of the environment where the code runs.
101+ *
102+ * @param dateStr - The date string to format.
103+ * @returns The formatted date and time string in the format `YYYY-MM-DD HH:mm:ss`.
104+ * Returns an empty string if the input is invalid or empty.
105+ */
106+ formatLocalFixedDateTime ( dateStr : string ) : string {
107+ if ( ! dateStr ) return "" ;
108+
109+ const date = new Date ( dateStr ) ;
110+ if ( isNaN ( date . getTime ( ) ) ) return "" ; // invalid date check
111+
112+ const year = date . getFullYear ( ) ;
113+ const month = String ( date . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) ;
114+ const day = String ( date . getDate ( ) ) . padStart ( 2 , '0' ) ;
115+
116+ const hours = String ( date . getHours ( ) ) . padStart ( 2 , '0' ) ;
117+ const minutes = String ( date . getMinutes ( ) ) . padStart ( 2 , '0' ) ;
118+ const seconds = String ( date . getSeconds ( ) ) . padStart ( 2 , '0' ) ;
119+
120+ return `${ year } -${ month } -${ day } ${ hours } :${ minutes } :${ seconds } ` ;
121+ }
122+
98123 /**
99124 * Formats a period between two dates
100125 *
You can’t perform that action at this time.
0 commit comments