diff --git a/flow-typed/box-ui-elements.js b/flow-typed/box-ui-elements.js index e7ed7e29b2..d49631d2d9 100644 --- a/flow-typed/box-ui-elements.js +++ b/flow-typed/box-ui-elements.js @@ -231,7 +231,7 @@ type MetadataTemplateField = { hidden?: boolean, key: string, type: string, -} +}; type MetadataEditorTemplate = { id: string, @@ -395,7 +395,7 @@ type FolderUploadItem = { status: UploadStatus, options?: UploadItemAPIOptions, isFolder?: boolean, -} +}; type UploadItem = { api: PlainUploadAPI | MultiputUploadAPI, @@ -649,7 +649,7 @@ type UploadDataTransferItemWithAPIOptions = { options?: UploadItemAPIOptions, }; -type UploadFile = File & { webkitRelativePath?: string }; +type UploadFile = File & { webkitRelativePath?: string, lastModifiedDate?: Date }; type DirectoryReader = { readEntries: (Function, Function) => void, @@ -691,16 +691,11 @@ type ElementsError = { }; type ErrorContextProps = { - onError: ( - error: ElementsXhrError | Error, - code: string, - contextInfo?: Object, - origin: ErrorOrigins, - ) => void, + onError: (error: ElementsXhrError | Error, code: string, contextInfo?: Object, origin: ErrorOrigins) => void, }; type ElementsErrorCallback = (e: ElementsXhrError, code: string, contextInfo?: Object) => void; type ClassificationInfo = { - Box__Security__Classification__Key?: string + Box__Security__Classification__Key?: string, } & MetadataInstance; diff --git a/src/util/__tests__/uploads-test.js b/src/util/__tests__/uploads-test.js index 7e38730e3f..dea1dbe849 100644 --- a/src/util/__tests__/uploads-test.js +++ b/src/util/__tests__/uploads-test.js @@ -45,12 +45,17 @@ describe('util/uploads', () => { // file with non-numeric lastModified (invalid Date) // file no lastModified test.each` - file | expectedResult - ${{ lastModified: 1483326245678 }} | ${'2017-01-02T03:04:05Z'} - ${{ lastModified: 'not a number' }} | ${null} - ${{ lastModified: new Date('2017-01-02T03:04:05.678Z') }} | ${'2017-01-02T03:04:05Z'} - ${{ lastModified: new Date('not valid') }} | ${null} - ${{}} | ${null} + file | expectedResult + ${{ lastModified: 1483326245678 }} | ${'2017-01-02T03:04:05Z'} + ${{ lastModified: 'not a number' }} | ${null} + ${{ lastModified: new Date('2017-01-02T03:04:05.678Z') }} | ${'2017-01-02T03:04:05Z'} + ${{ lastModified: new Date('not valid') }} | ${null} + ${{}} | ${null} + ${{ lastModifiedDate: 1483326245678 }} | ${'2017-01-02T03:04:05Z'} + ${{ lastModifiedDate: 'not a number' }} | ${null} + ${{ lastModifiedDate: new Date('2017-01-02T03:04:05.678Z') }} | ${'2017-01-02T03:04:05Z'} + ${{ lastModifiedDate: new Date('not valid') }} | ${null} + ${{}} | ${null} `( 'should return the properly formatted date when possible and return null otherwise', ({ file, expectedResult }) => { diff --git a/src/util/uploads.js b/src/util/uploads.js index 827aab658d..da0a993483 100644 --- a/src/util/uploads.js +++ b/src/util/uploads.js @@ -120,14 +120,14 @@ function toISOStringNoMS(date: Date): string { * @return {?string} */ function getFileLastModifiedAsISONoMSIfPossible(file: UploadFile): ?string { + // The compatibility chart at https://developer.mozilla.org/en-US/docs/Web/API/File/lastModified#Browser_compatibility + // is not up to date as of 12-13-2018. Edge & ie11 do not support lastModified, but support lastModifiedDate. + const lastModified = file.lastModified || file.lastModifiedDate; if ( - // $FlowFixMe https://github.com/facebook/flow/issues/6131 - file.lastModified && - (typeof file.lastModified === 'string' || - typeof file.lastModified === 'number' || - file.lastModified instanceof Date) + lastModified && + (typeof lastModified === 'string' || typeof lastModified === 'number' || lastModified instanceof Date) ) { - const lastModifiedDate = new Date(file.lastModified); + const lastModifiedDate = new Date(lastModified); if (isValidDateObject(lastModifiedDate)) { return toISOStringNoMS(lastModifiedDate); }