File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,12 @@ export interface IFullOptions extends ISharedOptions {
8282 */
8383 useLocaleFormat ?: boolean ;
8484
85+ /**
86+ * Should dates be output in ISO 8601 "Z" format:
87+ * @default false
88+ */
89+ useDateIso8601Format ?: boolean ;
90+
8591}
8692
8793export function json2csv ( data : object [ ] ,
Original file line number Diff line number Diff line change @@ -272,12 +272,15 @@ const Json2Csv = function(options) {
272272 * @returns {* }
273273 */
274274 function recordFieldValueToString ( fieldValue ) {
275- if ( Array . isArray ( fieldValue ) || utils . isObject ( fieldValue ) && ! utils . isDate ( fieldValue ) ) {
275+ const isD = utils . isDate ( fieldValue ) ; // store to avoid checking twice
276+ if ( Array . isArray ( fieldValue ) || utils . isObject ( fieldValue ) && ! isD ) {
276277 return JSON . stringify ( fieldValue ) ;
277278 } else if ( utils . isUndefined ( fieldValue ) ) {
278279 return 'undefined' ;
279280 } else if ( utils . isNull ( fieldValue ) ) {
280281 return 'null' ;
282+ } else if ( isD && options . useDateIso8601Format ) {
283+ return new Date ( fieldValue ) . toISOString ( ) ;
281284 } else {
282285 return ! options . useLocaleFormat ? fieldValue . toString ( ) : fieldValue . toLocaleString ( ) ;
283286 }
You can’t perform that action at this time.
0 commit comments