Pull out formatTimestamp into function

main
Mike Fix 6 years ago
parent d0d3589dc4
commit 0525a9fcca

@ -143,12 +143,7 @@ class Editor extends React.Component {
save({ id: format = 'png' }) { save({ id: format = 'png' }) {
const link = document.createElement('a') const link = document.createElement('a')
const timezoneOffset = (new Date()).getTimezoneOffset() * 60000 const timestamp = this.state.timestamp ? `_${formatTimestamp()}` : ''
const timeString = (new Date(Date.now() - timezoneOffset)).toISOString()
.slice(0, 19)
.replace(/:/g,'-')
.replace('T','_')
const timestamp = this.state.timestamp ? `_${timeString}` : ''
return this.getCarbonImage({ format, type: 'blob' }).then(url => { return this.getCarbonImage({ format, type: 'blob' }).then(url => {
link.download = `carbon${timestamp}.${format}` link.download = `carbon${timestamp}.${format}`
@ -292,6 +287,17 @@ class Editor extends React.Component {
} }
} }
function formatTimestamp() {
const timezoneOffset = (new Date()).getTimezoneOffset() * 60000
const timeString = (new Date(Date.now() - timezoneOffset)).toISOString()
.slice(0, 19)
.replace(/:/g,'-')
.replace('T','_')
return timeString;
}
function isImage(file) { function isImage(file) {
return file.type.split('/')[0] === 'image' return file.type.split('/')[0] === 'image'
} }

@ -501,5 +501,5 @@ export const DEFAULT_SETTINGS = {
titleBar: '', titleBar: '',
watermark: false, watermark: false,
squaredImage: false, squaredImage: false,
timestamp: true timestamp: false
} }

Loading…
Cancel
Save