Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

add new date.ts module and argument to getStars function #115

Merged
merged 2 commits into from
Dec 20, 2023

Conversation

grmbyrn
Copy link
Contributor

@grmbyrn grmbyrn commented Dec 3, 2023

Enhancements to Date Formatting and getStars Function

Changes Made:

  1. Date Formatting Module:

    • Moved the formatDate function into a separate module located at lib/utils/date.ts.
    • Implemented in lib/components/molecules/BlogPostCard.svelte, routes/(blog-article)/+layout.svelte and routes/rss.xml/+server.ts
    • The motivation is to centralise the date and time formatting logic and provide a single source of truth for date formatting across all components.
    • By using this helper function, we can easily update the date format in one place, affecting all components simultaneously.
    • This approach facilitates testing of date formatting independently of specific components.
    // src/lib/utils/date.ts
    import dateFormat from 'dateformat';
    
    export function formatDate(date: string): string {
      return dateFormat(date, 'UTC:dd/mm/yyyy');
    }
    
    export function formatTime(date: string): string {
     return dateFormat(date, 'UTC:HH:MM:ss');
    }
  2. getStars Function Modification:

    • Added an argument to the getStars function in the ProjectCard component (lib/components/molecules/ProjectCard.svelte).
    • The argument (repoName) replaces the previous usage of a global variable.
    • This change promotes better code organisation and maintainability by explicitly defining function inputs.
    • The modification improves the function's reusability and makes it more self-contained.

@grmbyrn grmbyrn requested a review from josecelano December 3, 2023 12:15
Copy link
Member

@josecelano josecelano left a comment

Choose a reason for hiding this comment

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

Hi @grmbyrn It looks good! You only need to rename an argument.

It would be nice in the future to add some unit tests. I would like to know how hard would be to setup unit testing in this project.

For Nuxt has been a pain.

src/lib/utils/date.ts Outdated Show resolved Hide resolved
Rename the argument in the `formatTime` function for clarity. The argument has been changed from `date` to `time` to better reflect its purpose and improve code readability.

This modification aligns with best practices and enhances the function's self-descriptiveness.
@josecelano
Copy link
Member

ACK d127462

@josecelano josecelano merged commit 7188eb7 into torrust:develop Dec 20, 2023
1 of 2 checks passed
@grmbyrn grmbyrn deleted the torrust-function branch March 6, 2024 15:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants