Skip to content

Commit

Permalink
* Update export data default filename to use today's date in local ti…
Browse files Browse the repository at this point in the history
…mezone instead of UTC (#3236)
  • Loading branch information
PikachuEXE committed Mar 2, 2023
1 parent f575d3c commit 5713e66
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/renderer/components/data-settings/data-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import { MAIN_PROFILE_ID } from '../../../constants'
import { calculateColorLuminance, getRandomColor } from '../../helpers/colors'
import {
copyToClipboard,
getTodayDateStrLocalTimezone,
readFileFromDialog,
showOpenDialog,
showSaveDialog,
showToast,
writeFileFromDialog
writeFileFromDialog,
} from '../../helpers/utils'
import { invidiousAPICall } from '../../helpers/api/invidious'
import { getLocalChannel } from '../../helpers/api/local'
Expand Down Expand Up @@ -509,8 +510,8 @@ export default defineComponent({
const subscriptionsDb = this.profileList.map((profile) => {
return JSON.stringify(profile)
}).join('\n') + '\n'// a trailing line is expected
const date = new Date().toISOString().split('T')[0]
const exportFileName = 'freetube-subscriptions-' + date + '.db'
const dateStr = getTodayDateStrLocalTimezone()
const exportFileName = 'freetube-subscriptions-' + dateStr + '.db'

const options = {
defaultPath: exportFileName,
Expand All @@ -526,8 +527,8 @@ export default defineComponent({
},

exportYouTubeSubscriptions: async function () {
const date = new Date().toISOString().split('T')[0]
const exportFileName = 'youtube-subscriptions-' + date + '.json'
const dateStr = getTodayDateStrLocalTimezone()
const exportFileName = 'youtube-subscriptions-' + dateStr + '.json'

const options = {
defaultPath: exportFileName,
Expand Down Expand Up @@ -579,8 +580,8 @@ export default defineComponent({
},

exportOpmlYouTubeSubscriptions: async function () {
const date = new Date().toISOString().split('T')[0]
const exportFileName = 'youtube-subscriptions-' + date + '.opml'
const dateStr = getTodayDateStrLocalTimezone()
const exportFileName = 'youtube-subscriptions-' + dateStr + '.opml'

const options = {
defaultPath: exportFileName,
Expand Down Expand Up @@ -612,8 +613,8 @@ export default defineComponent({
},

exportCsvYouTubeSubscriptions: async function () {
const date = new Date().toISOString().split('T')[0]
const exportFileName = 'youtube-subscriptions-' + date + '.csv'
const dateStr = getTodayDateStrLocalTimezone()
const exportFileName = 'youtube-subscriptions-' + dateStr + '.csv'

const options = {
defaultPath: exportFileName,
Expand All @@ -639,8 +640,8 @@ export default defineComponent({
},

exportNewPipeSubscriptions: async function () {
const date = new Date().toISOString().split('T')[0]
const exportFileName = 'newpipe-subscriptions-' + date + '.json'
const dateStr = getTodayDateStrLocalTimezone()
const exportFileName = 'newpipe-subscriptions-' + dateStr + '.json'

const options = {
defaultPath: exportFileName,
Expand Down Expand Up @@ -744,8 +745,8 @@ export default defineComponent({
const historyDb = this.historyCache.map((historyEntry) => {
return JSON.stringify(historyEntry)
}).join('\n') + '\n'
const date = new Date().toISOString().split('T')[0]
const exportFileName = 'freetube-history-' + date + '.db'
const dateStr = getTodayDateStrLocalTimezone()
const exportFileName = 'freetube-history-' + dateStr + '.db'

const options = {
defaultPath: exportFileName,
Expand Down Expand Up @@ -875,8 +876,8 @@ export default defineComponent({
},

exportPlaylists: async function () {
const date = new Date().toISOString().split('T')[0]
const exportFileName = 'freetube-playlists-' + date + '.db'
const dateStr = getTodayDateStrLocalTimezone()
const exportFileName = 'freetube-playlists-' + dateStr + '.db'

const options = {
defaultPath: exportFileName,
Expand Down
11 changes: 11 additions & 0 deletions src/renderer/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,3 +619,14 @@ export function toDistractionFreeTitle(title, minUpperCase = 3) {
export function formatNumber(number, options = undefined) {
return Intl.NumberFormat([i18n.locale.replace('_', '-'), 'en'], options).format(number)
}

export function getTodayDateStrLocalTimezone() {
const timeNow = new Date()
// `Date#getTimezoneOffset` returns the difference, in minutes
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset
const timeNowStr = new Date(timeNow.getTime() - (timeNow.getTimezoneOffset() * 60000)).toISOString()
// `Date#toISOString` returns string with `T` as date/time separator (ISO 8601 format)
// e.g. 2011-10-05T14:48:00.000Z
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
return timeNowStr.split('T')[0]
}

0 comments on commit 5713e66

Please sign in to comment.