Skip to content

Commit 4e1255d

Browse files
committed
correctly parse datetime format without fractional seconds if returned from backend
1 parent 25bf74a commit 4e1255d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

modules/vf-graphql-holochain/connection.ts

+4
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ function seralizeStringId(id: Array<Buffer | string>): string {
156156
}
157157

158158
const LONG_DATETIME_FORMAT = 'YYYY-MM-DDTHH:mm:ss.SSSZ'
159+
const SHORT_DATETIME_FORMAT = 'YYYY-MM-DDTHH:mm:ssZ'
159160
const isoDateRegex = /^\d{4}-\d\d-\d\d(T\d\d:\d\d:\d\d(\.\d\d\d)?)?([+-]\d\d:\d\d)?$/
160161

161162
/**
@@ -188,6 +189,9 @@ const decodeFields = (result: any): void => {
188189
// recursively check for Date strings and convert to JS date objects upon receiving
189190
if (value && value.match && value.match(isoDateRegex)) {
190191
subject[prop] = parse(value, LONG_DATETIME_FORMAT)
192+
if (subject[prop] === null) {
193+
subject[prop] = parse(value, SHORT_DATETIME_FORMAT)
194+
}
191195
}
192196

193197
})

0 commit comments

Comments
 (0)