Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

日付の表示形式変更 #135

Open
wants to merge 1 commit into
base: main-2023
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@prisma/client": "4.13.0",
"bootstrap": "5.2.3",
"cookie-parser": "1.4.6",
"dayjs": "1.11.7",
"debug": "4.3.4",
"express": "4.18.2",
"express-session": "1.17.3",
Expand Down
10 changes: 10 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ const router = express.Router();
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient({ log: [ 'query' ] });

const dayjs = require('dayjs');
const utc = require('dayjs/plugin/utc');
const timezone = require('dayjs/plugin/timezone');
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.tz.setDefault('Asia/Tokyo');

/* GET home page. */
router.get('/', async (req, res, next) => {
const title = '予定調整くん';
Expand All @@ -12,6 +19,9 @@ router.get('/', async (req, res, next) => {
where: { createdBy: parseInt(req.user.id) },
orderBy: { updatedAt: 'desc' }
});
schedules.forEach((schedule) => {
schedule.formattedUpdatedAt = dayjs(schedule.updatedAt).tz().format('YYYY/MM/DD HH:mm');
});
res.render('index', {
title: title,
user: req.user,
Expand Down
2 changes: 1 addition & 1 deletion views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ block content
tr
td
a(href=`/schedules/${schedule.scheduleId}`) #{schedule.scheduleName}
td #{schedule.updatedAt}
td #{schedule.formattedUpdatedAt}