feat-git #10

Merged
Hare merged 5 commits from feat-git into master 2024-09-25 23:30:09 +09:00
2 changed files with 22 additions and 15 deletions
Showing only changes of commit 7032c552a8 - Show all commits

View File

@ -3,22 +3,9 @@
if (typeof date === 'string') date = new Date(date); if (typeof date === 'string') date = new Date(date);
const pad = function (str: string): string { import { format } from "$lib/scripts/formatted_date";
return ('0' + str).slice(-2);
};
const year = date.getFullYear().toString(); const formattedDate = format(date);
const month = pad((date.getMonth() + 1).toString());
const day = pad(date.getDate().toString());
const hour = pad(date.getHours().toString());
const min = pad(date.getMinutes().toString());
const sec = pad(date.getSeconds().toString());
const tz = -date.getTimezoneOffset();
const sign = tz >= 0 ? '+' : '-';
const tzHour = pad((tz / 60).toString());
const tzMin = pad((tz % 60).toString());
let formattedDate = `${year}-${month}-${day}T${hour}:${min}:${sec}${sign}${tzHour}:${tzMin}`;
</script> </script>
{formattedDate} {formattedDate}

View File

@ -0,0 +1,20 @@
export const format = (
date: Date
) => {
const pad = function (str: string): string {
return ('0' + str).slice(-2);
};
const year = date.getFullYear().toString();
const month = pad((date.getMonth() + 1).toString());
const day = pad(date.getDate().toString());
const hour = pad(date.getHours().toString());
const min = pad(date.getMinutes().toString());
const sec = pad(date.getSeconds().toString());
const tz = -date.getTimezoneOffset();
const sign = tz >= 0 ? '+' : '-';
const tzHour = pad((tz / 60).toString());
const tzMin = pad((tz % 60).toString());
return `${year}-${month}-${day}T${hour}:${min}:${sec}${sign}${tzHour}:${tzMin}`;
};