refactor: change printDate to timestamp2text

This commit is contained in:
Artemy 2023-04-29 09:37:22 +03:00
parent 80858f53d9
commit 3f705bf8c4
7 changed files with 15 additions and 15 deletions

View file

@ -16,7 +16,7 @@
*/
import RenderMarkdown from "../components/markdown";
import { printDate } from "./utils";
import { timestamp2text } from "./utils";
function Note({ note }) {
return (
@ -26,7 +26,7 @@ function Note({ note }) {
{note.name}
</h2>
<div className="justify-self-center lg:justify-self-end">
{`${printDate(note.time)} ${
{`${timestamp2text(note.time)} ${
note.pub ? `| ${locals.PublicNote}` : `| ${locals.LocalNote}`
}`}
</div>

View file

@ -17,7 +17,7 @@
import { Locales } from "../localisation/main";
function printDate(time) {
function timestamp2text(time) {
time = new Date(time);
return time.toLocaleString(settings.language);
}
@ -48,4 +48,4 @@ async function getNetLocale(lang, fileName) {
return (await (await fetch(`localisation/${lang}/${fileName}`)).text()) || "";
}
export { printDate, reRenderPage, localesProcess, getNetLocale };
export { timestamp2text, reRenderPage, localesProcess, getNetLocale };

View file

@ -20,7 +20,7 @@ import { ChevronDoubleRightIcon } from "@heroicons/react/24/outline";
import { CheckBox } from "../components/checkbox";
import { useState } from "react";
import RenderMarkdown from "../components/markdown";
import { printDate } from "../components/utils";
import { timestamp2text } from "../components/utils";
import rehypeRemark from "rehype-remark/lib";
import ContentEditable from "react-contenteditable";
import ReactDOMServer from "react-dom/server";
@ -162,7 +162,7 @@ function CreateNote() {
{name}
</h2>
<div className="justify-self-center lg:justify-self-end">
{printDate(Date.now())}
{timestamp2text(Date.now())}
</div>
</div>
)}

View file

@ -17,7 +17,7 @@
import { ButtonWithIcon } from "../components/button";
import { ChevronDoubleRightIcon } from "@heroicons/react/24/outline";
import { printDate } from "../components/utils";
import { timestamp2text } from "../components/utils";
import Fuse from "fuse.js";
import { inputStyle } from "../components/styles";
import { useState } from "react";
@ -30,7 +30,7 @@ function Notes() {
let notes = Object.entries(notesObj);
for (let [id, note] of notes) {
note.id = id;
note.textTime = printDate(note.time);
note.textTime = timestamp2text(note.time);
notesObj[id] = note;
}
localStorage.setObj("Notes", notesObj);
@ -82,7 +82,7 @@ function Notes() {
{item.name}
</div>
<div className="grid grid-cols-1 lg:grid-cols-2 justify-self-center lg:justify-self-end">
<div className="text-center">{printDate(item.time)}</div>
<div className="text-center">{timestamp2text(item.time)}</div>
<div className="">
<ButtonWithIcon
href={`/notes/${item.id}`}

View file

@ -15,7 +15,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { printDate } from "../components/utils";
import { timestamp2text } from "../components/utils";
import { ChevronDoubleLeftIcon } from "@heroicons/react/24/outline";
import { ButtonWithIcon } from "../components/button";
import { useSearchParams } from "react-router-dom";
@ -39,7 +39,7 @@ function PubError() {
{locals.PubError}
</h2>
<div className="justify-self-center lg:justify-self-end">
{printDate(Date.now())}
{timestamp2text(Date.now())}
</div>
</div>
<div className="w-full md">{err ? err : locals.PubErrorMsg}</div>

View file

@ -18,7 +18,7 @@
import RenderMarkdown from "../components/markdown";
import { useState } from "react";
import { Navigate, useParams } from "react-router-dom";
import { printDate } from "../components/utils";
import { timestamp2text } from "../components/utils";
import { ChevronDoubleLeftIcon } from "@heroicons/react/24/outline";
import { ButtonWithIcon } from "../components/button";
@ -73,7 +73,7 @@ function PubNote() {
{note.name || "Загрузка..."}
</h2>
<div className="justify-self-center lg:justify-self-end">
{printDate(note.time || Date.now())}
{timestamp2text(note.time || Date.now())}
</div>
</div>
<div className="w-full md break-words">

View file

@ -16,7 +16,7 @@
*/
import { Navigate } from "react-router-dom";
import { printDate } from "../components/utils";
import { timestamp2text } from "../components/utils";
function uuidv4() {
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
@ -44,7 +44,7 @@ function Save() {
name,
text,
time,
textTime: printDate(time),
textTime: timestamp2text(time),
pubTime,
pub: !!pubTime,
};