From a5ee52f5c8b1ea024ac6a95978afb40fc00679dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hagen=20H=C3=BCbel?= Date: Thu, 27 Apr 2017 13:07:19 +0200 Subject: [PATCH] Fixed 'RCTJSONStringify() encountered the following error: Invalid type in JSON write (__NSTaggedDate)' --- FS.common.js | 4 ++-- RNFSManager.m | 4 ++-- android/src/main/java/com/rnfs/RNFSManager.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/FS.common.js b/FS.common.js index a205388..ace5727 100644 --- a/FS.common.js +++ b/FS.common.js @@ -161,8 +161,8 @@ function readFileGeneric(filepath: string, encodingOrOptions:?string, command: F function readDirGeneric(dirpath: string, command: Function) { return command(normalizeFilePath(dirpath)).then(files => { return files.map(file => ({ - created: file.created && new Date(file.created) || null, - modified: new Date(file.modified), + ctime: file.ctime && new Date(file.ctime * 1000) || null, + mtime: new Date(file.mtime * 1000), name: file.name, path: file.path, size: file.size, diff --git a/RNFSManager.m b/RNFSManager.m index 06df7f0..b2559de 100644 --- a/RNFSManager.m +++ b/RNFSManager.m @@ -52,8 +52,8 @@ RCT_EXPORT_METHOD(readDir:(NSString *)dirPath NSDictionary *attributes = [fileManager attributesOfItemAtPath:path error:nil]; return @{ - @"created": [attributes objectForKey:NSFileCreationDate], - @"modified": [attributes objectForKey:NSFileModificationDate], + @"ctime": [self dateToTimeIntervalNumber:(NSDate *)[attributes objectForKey:NSFileCreationDate]], + @"mtime": [self dateToTimeIntervalNumber:(NSDate *)[attributes objectForKey:NSFileModificationDate]], @"name": obj, @"path": path, @"size": [attributes objectForKey:NSFileSize], diff --git a/android/src/main/java/com/rnfs/RNFSManager.java b/android/src/main/java/com/rnfs/RNFSManager.java index ff6a3f0..5d00c00 100644 --- a/android/src/main/java/com/rnfs/RNFSManager.java +++ b/android/src/main/java/com/rnfs/RNFSManager.java @@ -259,7 +259,7 @@ public class RNFSManager extends ReactContextBaseJavaModule { for (File childFile : files) { WritableMap fileMap = Arguments.createMap(); - fileMap.putString("modified", childFile.lastModified()); + fileMap.putString("mtime", childFile.lastModified()); fileMap.putString("name", childFile.getName()); fileMap.putString("path", childFile.getAbsolutePath()); fileMap.putInt("size", (int)childFile.length());