Skip to content

fix: use datepipe for date formating#115

Draft
lukynmatuska wants to merge 7 commits intomasterfrom
114-používat-date-pipe-na-zobrazení-expirace-tokenů

Hidden character warning

The head ref may contain hidden characters: "114-pou\u017e\u00edvat-date-pipe-na-zobrazen\u00ed-expirace-token\u016f"
Draft

fix: use datepipe for date formating#115
lukynmatuska wants to merge 7 commits intomasterfrom
114-používat-date-pipe-na-zobrazení-expirace-tokenů

Conversation

@lukynmatuska
Copy link
Member

No description provided.

@lukynmatuska lukynmatuska linked an issue Sep 30, 2025 that may be closed by this pull request
@netlify
Copy link

netlify bot commented Sep 30, 2025

Deploy Preview for cutetix-admin ready!

Name Link
🔨 Latest commit dd02cea
🔍 Latest deploy log https://app.netlify.com/projects/cutetix-admin/deploys/68de3dfeb01b2f0008de4dea
😎 Deploy Preview https://deploy-preview-115--cutetix-admin.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@lukynmatuska lukynmatuska marked this pull request as ready for review September 30, 2025 12:05
Copy link
Collaborator

@sy-filis sy-filis left a comment

Choose a reason for hiding this comment

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

Ta DatePipe ti to naformátuje.
Části metody #formatCountdown jsou k ničemu...

@lukynmatuska
Copy link
Member Author

Ale to mi neukáže počet dní, nebo jo?
https://angular.dev/api/common/DatePipe#pre-defined-format-options

@sy-filis
Copy link
Collaborator

sy-filis commented Oct 2, 2025

Ukáže...
Ty si můžeš nastavit komplet svůj formát.

@lukynmatuska
Copy link
Member Author

I den ve smyslu odpočtu? Povedlo se mi tam nacpat den konce platnosti tokenu.

@sy-filis
Copy link
Collaborator

sy-filis commented Oct 2, 2025

Tak ten rozdíl si musíš samozřejmě vypočítat, uložit si jej jako Date nebo number a pak to pomocí té pipe naformátovat ve view.

@lukynmatuska
Copy link
Member Author

Rozdíl už mám v těch diff proměnných, nebo ne?

@lukynmatuska lukynmatuska added enhancement New feature or request help wanted Extra attention is needed labels Oct 2, 2025
@lukynmatuska lukynmatuska marked this pull request as draft October 3, 2025 20:32
@lukynmatuska lukynmatuska requested a review from Copilot February 28, 2026 16:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the user info UI to rely on Angular’s date pipe for formatting token expiration timestamps and countdown displays, with a configurable date format passed from the profile page.

Changes:

  • Adds a date_format input to UserInfoComponent and passes it from user-profile.
  • Switches token expiration rendering from Intl.DateTimeFormat to the Angular date pipe.
  • Changes countdown values from formatted strings to Date values and formats them via the date pipe.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.

File Description
src/app/user-profile/user-profile.component.html Passes a date format input into app-user-info.
src/app/components/user-info/component.ts Adds @Input + lifecycle hook, changes expiration/countdown types to Date, removes Intl formatting, adds interval init.
src/app/components/user-info/component.html Uses Angular date pipe to format expiration timestamps and countdown displays.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 26 to 36
@@ -25,45 +27,31 @@ export class UserInfoComponent implements OnDestroy {
const at_exp = this.#auth.getDecodedAccessToken()?.exp as number | undefined;
const rt_exp = this.#auth.getDecodedRefreshToken()?.exp as number | undefined;
if (!at_exp) {
this.time_to_access_token_expire = 'exp is not defined';
this.time_to_access_token_expire = new Date();
return;
}
if (!rt_exp) {
this.time_to_refresh_token_expire = 'exp is not defined';
this.time_to_refresh_token_expire = new Date();
return;
}
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

The early return when at_exp is missing prevents the refresh-token countdown from updating (and vice versa). Update access/refresh countdowns independently so one missing/expired token doesn’t leave the other field stale.

Copilot uses AI. Check for mistakes.
return `${m}:${pad(s)}`;
this.time_to_access_token_expire = new Date(at_diff);
this.time_to_refresh_token_expire = new Date(rt_diff);
console.log(this.time_to_refresh_token_expire, rt_exp, rt_diff);
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

Leftover console.log(...) in #updateCountdown() will spam the console every second and can leak token timing data. Please remove this or replace it with an appropriate, gated logging mechanism.

Suggested change
console.log(this.time_to_refresh_token_expire, rt_exp, rt_diff);

Copilot uses AI. Check for mistakes.
Comment on lines 42 to 49
if (at_diff <= 0) {
this.time_to_access_token_expire = 'EXPIRED';
this.time_to_access_token_expire = new Date();
return;
}

if (rt_diff <= 0) {
this.time_to_refresh_token_expire = 'EXPIRED';
this.time_to_refresh_token_expire = new Date();
return;
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

When the countdown is expired (*_diff <= 0), time_to_*_expire is set to new Date(), which will render as a valid time/duration instead of “EXPIRED”. Prefer null plus a fallback string (or a dedicated status field) so the UI reflects the expired state accurately.

Copilot uses AI. Check for mistakes.

constructor() {
this.#refreshingInterval = window.setInterval(() => { this.#updateCountdown(); }, 1_000)
@Input() date_format: string = 'medium';
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

date_format as an @Input name (and corresponding attribute) deviates from the codebase’s existing camelCase input naming (e.g., autosaveDebounce, placeholder). Consider renaming this input to dateFormat and updating call sites accordingly for consistency and to better align with Angular style.

Suggested change
@Input() date_format: string = 'medium';
@Input() dateFormat: string = 'medium';

Copilot uses AI. Check for mistakes.
<div class="info" label="Access token expires on">{{access_token_expire | date: date_format}} ‒
{{time_to_access_token_expire | date: "m:ss" : "+0000" }}</div>
<div class="info" label="Refresh token expires on">{{refresh_token_expire | date: date_format}} ‒
{{time_to_refresh_token_expire | date: "d:hh:mm:ss" : "+0000"}}</div> No newline at end of file
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

The countdown values are being represented as new Date(at_diff) / new Date(rt_diff) and then formatted with the date pipe. This treats the remaining milliseconds as an absolute timestamp since the Unix epoch, which leads to incorrect duration rendering (minutes wrap every hour, and d is day-of-month rather than “days remaining”). Consider keeping the prior explicit duration formatting logic or introducing a dedicated “duration” formatter (pipe/helper) that formats a millisecond delta into d hh:mm:ss reliably.

Suggested change
{{time_to_refresh_token_expire | date: "d:hh:mm:ss" : "+0000"}}</div>
{{time_to_refresh_token_expire | date: "HH:mm:ss" : "+0000"}}</div>

Copilot uses AI. Check for mistakes.
Comment on lines 27 to 35
const at_exp = this.#auth.getDecodedAccessToken()?.exp as number | undefined;
const rt_exp = this.#auth.getDecodedRefreshToken()?.exp as number | undefined;
if (!at_exp) {
this.time_to_access_token_expire = 'exp is not defined';
this.time_to_access_token_expire = new Date();
return;
}
if (!rt_exp) {
this.time_to_refresh_token_expire = 'exp is not defined';
this.time_to_refresh_token_expire = new Date();
return;
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

When at_exp/rt_exp are missing, the code sets time_to_*_expire to new Date(), which will render as “now” (misleading). Prefer a sentinel like null plus a template fallback (e.g., "exp is not defined") or a separate status field.

Copilot uses AI. Check for mistakes.
<div class="details">
<h1>User details</h1>
<app-user-info></app-user-info>
<app-user-info date_format="full"></app-user-info>
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

Passing date_format as a component attribute introduces a snake_case input name that appears inconsistent with other component inputs in this codebase (which use camelCase). If the input is renamed to dateFormat, update this usage as well.

Suggested change
<app-user-info date_format="full"></app-user-info>
<app-user-info dateFormat="full"></app-user-info>

Copilot uses AI. Check for mistakes.
Comment on lines +75 to +78
get access_token_expire() {
const exp = this.#auth.getDecodedAccessToken()?.exp;
if (!exp) return 'undefined';

const userLocale = navigator.languages?.[0] || navigator.language || 'cs-CZ';
return new Intl.DateTimeFormat(
userLocale,
{
dateStyle: 'short',
timeStyle: 'medium'
}
).format(new Date(exp * 1000));
return new Date(exp * 1000);
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

access_token_expire returns the string 'undefined' when exp is missing, but the template now pipes access_token_expire through the date pipe. Piping a non-date value can trigger an InvalidPipeArgument runtime error. Return null/undefined (or Date | null) instead and handle the missing case in the template.

Copilot uses AI. Check for mistakes.
Comment on lines +81 to +84
get refresh_token_expire() {
const exp = this.#auth.getDecodedRefreshToken()?.exp;
if (!exp) return 'undefined';

const userLocale = navigator.languages?.[0] || navigator.language || 'cs-CZ';
return new Intl.DateTimeFormat(
userLocale,
{
dateStyle: 'short',
timeStyle: 'medium'
}
).format(new Date(exp * 1000));
return new Date(exp * 1000);
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

refresh_token_expire returns the string 'undefined' when exp is missing, but the template pipes it through the date pipe. Return null/undefined (or Date | null) and render a non-piped fallback string in the template for the missing case.

Copilot uses AI. Check for mistakes.
@netlify
Copy link

netlify bot commented Feb 28, 2026

Deploy Preview for cutetix-admin ready!

Name Link
🔨 Latest commit e253cc0
🔍 Latest deploy log https://app.netlify.com/projects/cutetix-admin/deploys/69a31c177120ed0008d814a8
😎 Deploy Preview https://deploy-preview-115--cutetix-admin.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Používat date pipe na zobrazení expirace tokenů

3 participants