Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Issue #1054 - Replacing moment by dayjs #1067

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Abanoub321
Copy link

No description provided.

Copy link
Owner

@Zenoo Zenoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having to extend dayjs every time we need to use it is not a good option.
Please follow the steps here to globally extend dayjs:
iamkun/dayjs#1577

This will have to be done both in the server and client packages

@Abanoub321 Abanoub321 requested a review from Zenoo November 27, 2024 14:38
Copy link
Owner

@Zenoo Zenoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure using the method I linked above, we do not need to import from a custom dayjs file to get the extensions working.

import dayjs from '../../utils/dayjs'; should be import dayjs from 'dayjs'; everywhere

@Abanoub321 Abanoub321 requested a review from Zenoo November 27, 2024 18:24
Copy link
Owner

@Zenoo Zenoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you misunderstood, I don't want to have to import dayjs from an utils, I want to be able to have import dayjs from 'dayjs'; and have it already extended, the issue I linked explains how

dayjs.extend(relativeTime);
dayjs.extend(utc);

export default dayjs;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid exporting it to prevent picking it as a reference when using it in other files

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert your changes to this file, the diff contains a lot of file formatting, only keep changes regarding moment/dayjs

@@ -16,13 +16,13 @@ const GlobalTournamentView = () => {
return (
<Page title={`${bruteName || ''} ${t('MyBrute')}`} headerUrl={`/${bruteName || ''}/cell`}>
<Paper sx={{ mx: 4 }}>
<Text h3 bold upperCase typo="handwritten" sx={{ mr: 2 }}>{t('globalTournamentOf')} {moment.utc(date).format('DD/MM/YYYY')}</Text>
<Text h3 bold upperCase typo="handwritten" sx={{ mr: 2 }}>{t('globalTournamentOf')} {dayjs(date).format('DD/MM/YYYY')}</Text>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Text h3 bold upperCase typo="handwritten" sx={{ mr: 2 }}>{t('globalTournamentOf')} {dayjs(date).format('DD/MM/YYYY')}</Text>
<Text h3 bold upperCase typo="handwritten" sx={{ mr: 2 }}>{t('globalTournamentOf')} {dayjs.utc(date).format('DD/MM/YYYY')}</Text>

@@ -32,7 +32,7 @@ const PatchNotesView = () => {
</Paper>
{displayedReleases.map((release) => (
<Paper key={release.version} sx={{ bgcolor: 'background.paperLight', my: 3 }}>
<Text h4 bold upperCase>v{release.version} <Text component="span" italic upperCase>{moment(release.date).format('DD MMMM YYYY')}</Text></Text>
<Text h4 bold upperCase>v{release.version} <Text component="span" italic upperCase>{dayjs(release.date).format('DD MMMM YYYY')}</Text></Text>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original was missing the utc usage

Suggested change
<Text h4 bold upperCase>v{release.version} <Text component="span" italic upperCase>{dayjs(release.date).format('DD MMMM YYYY')}</Text></Text>
<Text h4 bold upperCase>v{release.version} <Text component="span" italic upperCase>{dayjs.utc(release.date).format('DD MMMM YYYY')}</Text></Text>

@@ -177,7 +177,7 @@ const ClanThreadView = () => {
<Box component="img" src="/images/clan/master.gif" sx={{ ml: 1, width: 7 }} />
)}
</Box>
<Text color="primary">{moment(post.date).format('D MMM YYYY HH:mm')}</Text>
<Text color="primary">{dayjs(post.date).format('D MMM YYYY HH:mm')}</Text>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing utc in the original code

Suggested change
<Text color="primary">{dayjs(post.date).format('D MMM YYYY HH:mm')}</Text>
<Text color="primary">{dayjs.utc(post.date).format('D MMM YYYY HH:mm')}</Text>

@@ -1,7 +1,7 @@
import {
Event, EventStatus, FightModifier, PrismaClient,
} from '@labrute/prisma';
import moment from 'moment';
import dayjs from './dayjs.js';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import dayjs from './dayjs.js';
import dayjs from 'dayjs';

import translate from './translate.js';
import ServerState from './ServerState.js';
import dayjs from './dayjs.js';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import dayjs from './dayjs.js';
import dayjs from 'dayjs';

import ServerState from '../ServerState.js';
import translate from '../translate.js';
import checkLevelUpAchievements from './checkLevelUpAchievements.js';
import getOpponents from './getOpponents.js';
import { removeChoiceFromDestiny } from './removeChoiceFromDestiny.js';
import dayjs from '../dayjs.js';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import dayjs from '../dayjs.js';
import dayjs from 'dayjs';

dayjs.extend(utc);
dayjs.extend(isSameOrBefore);

export default dayjs;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export default dayjs;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this file being imported anywhere, shouldn't it be imported in the core index file?

@Zenoo
Copy link
Owner

Zenoo commented Jan 13, 2025

Are you still working on this @Abanoub321 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants