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

fix(dates): store in UTC but display in local french #338

Merged
merged 1 commit into from
Sep 18, 2024
Merged

Conversation

lwih
Copy link
Collaborator

@lwih lwih commented Sep 12, 2024

Pas mal de choses assez importantes ici.

Côté Backend :

  • tout ce qui vient de Monitor, dans le folder infra est en ZonedDateTime parce que c'est ce qu'ils envoient
  • tout le reste du backend utilise Instant "An instantaneous point on the time-line UTC"
  • toutes nos API enverront et recevront donc des dates en UTC
  • côté GraphQL j'en ai profité pour créer un type Instant pour que ce soit clair qu'on utilise une date

Côté Client:

Charge aux client de gérer ça à leur souhaits ces dates UTC à leur souhait

  • Rapport de patrouille: calcul des durées direct en UTC - afficher la timeline en local datetime
  • AEM: calcul des durées direct en UTC
  • Frontend: là il faut transformer en local pour afficher puis repasser en UTC pour envoyer au backend
    J'ai mis en place 2 Apollo Links (ou middleware) qui se chargent de transformer les dates au niveau des Queries et Mutations

Le truc relou

Je suis pas mécontent de ce grand coup de ménage mais y a un truc qui me les a bien brisé, c'est le DatePicker de Monitor. En effet, il retransforme les dates de son côté donc je perdais la timezone. J'ai donc dû créer une couche sur le DatePicker et le DateRangePicker qui rajoute encore une fois la timezone.
Du coup, il faut utiliser ces DatePicker et non ceux venant de Monitor

Autres remarques:

  • j'en ai profité pour split tous les Apollo Link dans des ficheirs à part et j'en ai testé quelques uns
  • j'ai bien harmonisé tous les schemas GraphQLet les Input coté backend au niveau des dates

@lwih lwih force-pushed the dates-utc branch 2 times, most recently from 4c324c7 to 6fd19e2 Compare September 12, 2024 14:30
Copy link

# npm audit report

path-to-regexp  4.0.0 - 7.2.0
Severity: high
path-to-regexp outputs backtracking regular expressions - https://github.com/advisories/GHSA-9wv6-86v2-598j
fix available via `npm audit fix --force`
Will install [email protected], which is a breaking change
node_modules/path-to-regexp
  msw  <=0.0.1 || >=0.36.0
  Depends on vulnerable versions of path-to-regexp
  node_modules/msw

2 high severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

Copy link

github-actions bot commented Sep 12, 2024

Coverage Report for frontend

Status Category Percentage Covered / Total
🟢 Lines 78.89% (🎯 50%) 1899 / 2407
🟢 Statements 78.53% (🎯 50%) 1976 / 2516
🟢 Functions 75.64% (🎯 50%) 500 / 661
🟢 Branches 71.19% (🎯 50%) 813 / 1142
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
frontend/src/app.tsx 92.3% 50% 100% 92.3% 51-61
frontend/src/index.tsx 0% 100% 100% 0% 15, 18, 20-25
frontend/src/apollo-client/apollo-client.ts 100% 50% 100% 100%
frontend/src/apollo-client/links/auth-link.ts 25% 0% 0% 25% 5-13
frontend/src/apollo-client/links/error-link.ts 28.57% 0% 0% 28.57% 7, 9-12, 10-11, 14
frontend/src/apollo-client/links/log-time-link.ts 100% 100% 100% 100%
frontend/src/apollo-client/links/mutation-date-converter-link.ts 100% 100% 100% 100%
frontend/src/apollo-client/links/query-date-converter-link.ts 100% 100% 100% 100%
frontend/src/features/common/components/elements/date-picker.tsx 72.22% 57.14% 75% 72.22% 11, 23, 41-44, 43
frontend/src/features/common/components/elements/daterange-picker.tsx 55.55% 33.33% 50% 55.55% 17-25, 18-24, 23
frontend/src/features/common/components/elements/patchable-monitor-daterange.tsx 37.5% 0% 33.33% 37.5% 20-24, 21-23, 34
frontend/src/features/common/utils/dates-for-machines.ts 94.73% 92.3% 100% 94.73% 37, 62
frontend/src/features/common/utils/localstorage-mock.ts 100% 100% 100% 100%
frontend/src/features/pam/mission/components/elements/mission-content.tsx 30.43% 11.11% 18.18% 30.43% 55, 60, 64-84, 65-84, 67-84, 69-84, 71-84, 73-84, 75-84, 77-84, 79-84, 81-84, 83, 88-94, 96-100, 103, 107, 109-115, 117-118, 121, 123-126, 128-129, 133-141, 145-152, 156-161, 164-191, 166-168, 170-172, 174-176, 178-180, 182-184, 186-188, 190, 307
frontend/src/features/pam/mission/components/elements/mission-item.tsx 81.81% 77.77% 75% 81.39% 60, 63-64, 67, 82-87, 103, 116
frontend/src/features/pam/mission/components/elements/actions/action-anti-pollution-form.tsx 68% 50% 61.11% 65.95% 50, 53, 59, 63, 69-74, 76-79, 98-103, 154, 173, 213, 225, 237, 259
frontend/src/features/pam/mission/components/elements/actions/action-baaem-permanence-form.tsx 54.28% 37.5% 25% 55.88% 35, 38, 44, 48, 51-75, 53-64, 54-59, 61-63, 66-72, 74, 78-83, 115, 137
frontend/src/features/pam/mission/components/elements/actions/action-control-nav.tsx 90.38% 61.11% 85.71% 90.19% 83-88, 194, 230
frontend/src/features/pam/mission/components/elements/actions/action-header.tsx 100% 100% 100% 100%
frontend/src/features/pam/mission/components/elements/actions/action-illegal-immigration-form.tsx 47.72% 43.75% 23.07% 48.83% 41, 44, 50, 54, 57-86, 59-75, 60-75, 67-70, 72-74, 77-83, 85, 89-94, 126, 141-143, 142, 166, 182, 196, 223
frontend/src/features/pam/mission/components/elements/actions/action-nautical-event-form.tsx 54.28% 37.5% 25% 55.88% 35, 38, 44, 48, 51-75, 53-64, 54-59, 61-63, 66-72, 74, 78-83, 116, 138
frontend/src/features/pam/mission/components/elements/actions/action-note-form.tsx 80% 100% 37.5% 82.75% 42, 46, 49-56, 50-55, 96
frontend/src/features/pam/mission/components/elements/actions/action-public-order-form.tsx 54.28% 37.5% 25% 55.88% 35, 38, 44, 48, 51-75, 53-64, 54-59, 61-63, 66-72, 74, 78-83, 115, 137
frontend/src/features/pam/mission/components/elements/actions/action-representation-form.tsx 54.28% 37.5% 25% 55.88% 35, 38, 44, 48, 51-75, 53-64, 54-59, 61-63, 66-72, 74, 78-83, 115, 137
frontend/src/features/pam/mission/components/elements/actions/action-rescue-form.tsx 54.92% 50% 31.81% 54.28% 44, 47, 53, 57, 61, 65, 71-76, 78-81, 87-102, 88-102, 93-97, 99-101, 121-123, 128-133, 167, 186, 222, 242, 252, 280, 300, 315, 350, 376, 395, 405
frontend/src/features/pam/mission/components/elements/actions/action-status-form.tsx 93.54% 77.77% 77.77% 93.33% 109, 117
frontend/src/features/pam/mission/components/elements/actions/action-vigimer-form.tsx 54.28% 37.5% 25% 55.88% 35, 38, 44, 48, 51-75, 53-64, 54-59, 61-63, 66-72, 74, 78-83, 116, 138
frontend/src/features/pam/mission/components/elements/timeline/timeline.tsx 100% 95% 100% 100%
frontend/src/features/pam/mission/components/layout/page-footer.tsx 66.66% 50% 50% 66.66% 24-25
frontend/src/features/pam/mission/hooks/use-is-mission-complete-for-stats.tsx 85.71% 100% 100% 85.71% 32
frontend/src/features/pam/mission/hooks/use-is-mission-finished.tsx 80% 100% 100% 80% 30
frontend/src/features/pam/mission/utils/utils.ts 100% 100% 100% 100%
frontend/src/pages/mission-page.tsx 45.65% 41.66% 60% 46.66% 40-70, 41-69, 42, 44, 47-50, 48-49, 53, 56-58, 61-62, 65, 67-68, 74-75, 77-87, 78-87, 85-86
Generated in workflow #1027

@MTES-MCT MTES-MCT deleted a comment from github-actions bot Sep 13, 2024
@MTES-MCT MTES-MCT deleted a comment from github-actions bot Sep 13, 2024
@lwih lwih marked this pull request as ready for review September 16, 2024 09:47
@lwih lwih changed the title Dates utc fix(dates): store in UTC but display in local french Sep 16, 2024
if (endDateTime.isAfter(compareDate)) {
return MissionStatusEnum.IN_PROGRESS
} else if (endDateTime.isBefore(compareDate) || endDateTime.isEqual(compareDate)) {
} else if (endDateTime.isBefore(compareDate) || endDateTime == compareDate) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pourquoi == a la place de isEqual?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Je sais plus, c'est un des code linters qui m'a conseillé ça mais je trouve bizarre que le linter ne se plaigne pas de isBefore, je vais re-regarder

Copy link
Collaborator

Choose a reason for hiding this comment

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

le truc c'est que en java le == compare les adresses dans la JVM et le Equal les valeurs des objets... dans le doute utilisons les méthodes fournies.. sinon on est tout bon

@lwih lwih merged commit 3a2132a into main Sep 18, 2024
9 checks passed
@lwih lwih deleted the dates-utc branch September 18, 2024 09:38
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