File tree Expand file tree Collapse file tree
adminforth/dataConnectors Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -205,8 +205,14 @@ class PostgresConnector extends AdminForthBaseConnector implements IAdminForthDa
205205 if ( ! value ) {
206206 return null ;
207207 }
208- if ( field . _underlineType == 'timestamp' || field . _underlineType == 'int' ) {
209- return dayjs ( value . replace ( ' ' , 'T' ) + 'Z' ) . toISOString ( ) ;
208+ if ( field . _underlineType == 'timestamp' ) {
209+ if ( typeof value == 'string' ) {
210+ const normalizedValue = value . includes ( ' ' ) ? `${ value . replace ( ' ' , 'T' ) } Z` : value ;
211+ return dayjs ( normalizedValue ) . toISOString ( ) ;
212+ }
213+ return dayjs ( value ) . toISOString ( ) ;
214+ } else if ( field . _underlineType == 'int' ) {
215+ return dayjs . unix ( + value ) . toISOString ( ) ;
210216 } else if ( field . _underlineType == 'varchar' ) {
211217 return dayjs ( value ) . toISOString ( ) ;
212218 } else {
Original file line number Diff line number Diff line change 1+ import { AdminForthDataTypes } from '../../adminforth/index.js' ;
2+ import PostgresConnector from '../../adminforth/dataConnectors/postgres.js' ;
3+
4+ describe ( 'PostgresConnector DATETIME normalization' , ( ) => {
5+ const connector = new PostgresConnector ( ) ;
6+ const timestampField = {
7+ type : AdminForthDataTypes . DATETIME ,
8+ _underlineType : 'timestamp' ,
9+ name : 'created_at' ,
10+ table : 'adminuser' ,
11+ } as any ;
12+
13+ it ( 'parses raw postgres timestamp strings as UTC' , ( ) => {
14+ expect ( connector . getFieldValue ( timestampField , '2026-05-09 17:09:21.622' ) ) . toBe ( '2026-05-09T17:09:21.622Z' ) ;
15+ } ) ;
16+
17+ it ( 'accepts Date objects returned by pg timestamp parsers' , ( ) => {
18+ expect ( connector . getFieldValue ( timestampField , new Date ( '2026-05-09T17:09:21.622Z' ) ) ) . toBe ( '2026-05-09T17:09:21.622Z' ) ;
19+ } ) ;
20+ } ) ;
You can’t perform that action at this time.
0 commit comments