From 94ce852eb40615a3d139e179361038d41a1d216b Mon Sep 17 00:00:00 2001 From: Rustem Mussabekov Date: Tue, 18 Feb 2025 16:40:36 +0300 Subject: [PATCH] - Fix current local date format - Add warning to merge collections - Change format of date tag in save tabs --- package.json | 2 +- src/co/collections/items/selectMode.js | 2 +- src/modules/format/date/index.js | 3 +- src/modules/format/date/long.js | 3 +- src/modules/format/date/longTime.js | 3 +- src/modules/format/date/month.js | 3 +- src/modules/format/date/numeric.js | 39 ++++++++++++++++++++++++++ src/modules/format/date/short.js | 3 +- src/modules/format/date/shortTime.js | 3 +- src/routes/extension/tabs/index.js | 4 +-- 10 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 src/modules/format/date/numeric.js diff --git a/package.json b/package.json index 529ffb0a..80d5d66f 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "app", - "version": "5.6.71", + "version": "5.6.72", "description": "All-in-one bookmark manager", "author": "Rustem Mussabekov", "license": "MIT", diff --git a/src/co/collections/items/selectMode.js b/src/co/collections/items/selectMode.js index a8dd958f..d7731a48 100644 --- a/src/co/collections/items/selectMode.js +++ b/src/co/collections/items/selectMode.js @@ -17,7 +17,7 @@ export default class CollectionsSelectMode extends React.Component { onMergeSelected = async()=>{ const { selectMode: { ids }, actions: { mergeSelected } } = this.props - if (await Confirm(`${t.s('areYouSure')}\n${t.s('merge')} ${ids.length} ${t.s('collectionsCount')}`)) + if (await Confirm(`${t.s('areYouSure')}\n${t.s('merge')} ${ids.length} ${t.s('collectionsCount')}.\nAll selected collections will be merged into one.`)) mergeSelected() } diff --git a/src/modules/format/date/index.js b/src/modules/format/date/index.js index 4584f1e4..e6147380 100644 --- a/src/modules/format/date/index.js +++ b/src/modules/format/date/index.js @@ -3,4 +3,5 @@ export * from './short' export * from './long' export * from './longTime' export * from './month' -export * from './shortTime' \ No newline at end of file +export * from './shortTime' +export * from './numeric' \ No newline at end of file diff --git a/src/modules/format/date/long.js b/src/modules/format/date/long.js index 50e31b0c..e6cb16c8 100644 --- a/src/modules/format/date/long.js +++ b/src/modules/format/date/long.js @@ -1,5 +1,4 @@ import React from 'react' -import t from '~t' import { parseDate } from './parse' import dateFnsFormat from 'date-fns/format' @@ -7,7 +6,7 @@ let _format function getFormat() { if (!_format) _format = new Intl.DateTimeFormat( - t.currentLang, + undefined, { year: 'numeric', month: 'long', diff --git a/src/modules/format/date/longTime.js b/src/modules/format/date/longTime.js index 01491e43..a47778bc 100644 --- a/src/modules/format/date/longTime.js +++ b/src/modules/format/date/longTime.js @@ -1,5 +1,4 @@ import React from 'react' -import t from '~t' import { parseDate } from './parse' import dateFnsFormat from 'date-fns/format' @@ -7,7 +6,7 @@ let _format function getFormat() { if (!_format) _format = new Intl.DateTimeFormat( - t.currentLang, + undefined, { hour12: new Date().toLocaleTimeString().toString().match(/am|pm/i) ? true : false, year: 'numeric', diff --git a/src/modules/format/date/month.js b/src/modules/format/date/month.js index c44e60c7..6ee03bff 100644 --- a/src/modules/format/date/month.js +++ b/src/modules/format/date/month.js @@ -1,5 +1,4 @@ import React from 'react' -import t from '~t' import { parseDate } from './parse' import dateFnsFormat from 'date-fns/format' @@ -7,7 +6,7 @@ let _format function getFormat() { if (!_format) _format = new Intl.DateTimeFormat( - t.currentLang, + undefined, { year: 'numeric', month: 'long', diff --git a/src/modules/format/date/numeric.js b/src/modules/format/date/numeric.js new file mode 100644 index 00000000..611cba45 --- /dev/null +++ b/src/modules/format/date/numeric.js @@ -0,0 +1,39 @@ +import React from 'react' +import { parseDate } from './parse' +import dateFnsFormat from 'date-fns/format' + +let _format +function getFormat() { + if (!_format) + _format = new Intl.DateTimeFormat( + undefined, + { + year: 'numeric', + month: 'numeric', + day: 'numeric', + } + ).format + + return _format +} + +export const numericDate = (original) => { + let d + try{ d = parseDate(original) } catch(e){} + + try{ + return getFormat()(d) + }catch(e){} + + try{ + return dateFnsFormat(d, 'P') + }catch(e){} + + return '' +} + +export const NumericDate = React.memo( + function({ date }) { + return numericDate(date) + } +) \ No newline at end of file diff --git a/src/modules/format/date/short.js b/src/modules/format/date/short.js index c92b08b3..2c611440 100644 --- a/src/modules/format/date/short.js +++ b/src/modules/format/date/short.js @@ -1,5 +1,4 @@ import React from 'react' -import t from '~t' import isToday from 'date-fns/isToday' import isThisYear from 'date-fns/isThisYear' import dateFnsFormat from 'date-fns/format' @@ -17,7 +16,7 @@ function getFormat(type) { default: params = { year: 'numeric', month: 'short', day: 'numeric' }; break; } - _formats[type] = new Intl.DateTimeFormat(t.currentLang, { hour12, ...params }).format + _formats[type] = new Intl.DateTimeFormat(undefined, { hour12, ...params }).format } return _formats[type] diff --git a/src/modules/format/date/shortTime.js b/src/modules/format/date/shortTime.js index 7b0e8770..0b17a9af 100644 --- a/src/modules/format/date/shortTime.js +++ b/src/modules/format/date/shortTime.js @@ -1,5 +1,4 @@ import React from 'react' -import t from '~t' import { parseDate } from './parse' import dateFnsFormat from 'date-fns/format' @@ -7,7 +6,7 @@ let _format function getFormat() { if (!_format) _format = new Intl.DateTimeFormat( - t.currentLang, + undefined, { hour12: new Date().toLocaleTimeString().toString().match(/am|pm/i) ? true : false, year: 'numeric', diff --git a/src/routes/extension/tabs/index.js b/src/routes/extension/tabs/index.js index a9c1e760..626cb87a 100644 --- a/src/routes/extension/tabs/index.js +++ b/src/routes/extension/tabs/index.js @@ -2,7 +2,7 @@ import React, { useState } from 'react' import { useParams } from 'react-router-dom' import Screen from '~co/screen/basic' import { Layout, Separator } from '~co/common/form' -import { longDate } from '~modules/format/date' +import { numericDate } from '~modules/format/date' import useTabs, { preload } from './useTabs' import useSubmit from './useSubmit' @@ -19,7 +19,7 @@ export default function ExtensionTabsScreen() { const params = useParams() const [tabs, setTabs] = useTabs() const [collectionId, setCollectionId] = useState(params.collectionId) - const [tags, setTags] = useState(()=>[longDate(new Date()).replace(/,/g, ' ')]) + const [tags, setTags] = useState(()=>[numericDate(new Date())]) const [close, setClose] = useState(true) const {onSubmit, loading} = useSubmit({ tabs, collectionId, tags, close })