Skip to content

Commit

Permalink
refactor: extraction de la fonction getDuration dans un fichier utili…
Browse files Browse the repository at this point in the history
…taire
  • Loading branch information
ecnivtwelve committed Jan 20, 2025
1 parent a2ffec3 commit e5533c5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
12 changes: 12 additions & 0 deletions src/utils/format/course_duration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const lz = (num: number) => (num < 10 ? `0${num}` : num);

export const getDuration = (minutes: number): string => {
const durationHours = Math.floor(minutes / 60);
const durationRemainingMinutes = minutes % 60;

if(durationHours === 0) {
return `${durationRemainingMinutes} min`;
}

return `${durationHours}h ${lz(durationRemainingMinutes)}min`;
};
9 changes: 1 addition & 8 deletions src/views/account/Lessons/Atoms/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@ import Reanimated, {
import NativeTouchable from "@/components/Global/NativeTouchable";
import { getSubjectData } from "@/services/shared/Subject";
import { animPapillon } from "@/utils/ui/animations";

const lz = (num: number) => (num < 10 ? `0${num}` : num);

const getDuration = (minutes: number): string => {
const durationHours = Math.floor(minutes / 60);
const durationRemainingMinutes = minutes % 60;
return `${durationHours} h ${lz(durationRemainingMinutes)} min`;
};
import { getDuration } from "@/utils/format/course_duration";

export const TimetableItem: React.FC<{
item: TimetableClass
Expand Down
9 changes: 1 addition & 8 deletions src/views/account/Lessons/Atoms/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { animPapillon } from "@/utils/ui/animations";
import LessonsLoading from "./Loading";
import MissingItem from "@/components/Global/MissingItem";
import { getHolidayEmoji } from "@/utils/format/holidayEmoji";
import { getDuration } from "@/utils/format/course_duration";

const emoji = getHolidayEmoji();

Expand All @@ -24,14 +25,6 @@ const RefreshControl = createNativeWrapper(RNRefreshControl, {
shouldCancelWhenOutside: false,
});

const lz = (num: number) => (num < 10 ? `0${num}` : num);

const getDuration = (minutes: number): string => {
const durationHours = Math.floor(minutes / 60);
const durationRemainingMinutes = minutes % 60;
return `${durationHours} h ${lz(durationRemainingMinutes)} min`;
};

interface PageProps {
current: boolean
date: Date
Expand Down
9 changes: 1 addition & 8 deletions src/views/account/Lessons/Document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,7 @@ import { useClassSubjectStore } from "@/stores/classSubject";
import { useCurrentAccount } from "@/stores/account";
import { AccountService } from "@/stores/account/types";
import getAndOpenFile from "@/utils/files/getAndOpenFile";

const lz = (num: number) => (num < 10 ? `0${num}` : num);

const getDuration = (minutes: number): string => {
const durationHours = Math.floor(minutes / 60);
const durationRemainingMinutes = minutes % 60;
return `${durationHours}h ${lz(durationRemainingMinutes)} min`;
};
import { getDuration } from "@/utils/format/course_duration";

const LessonDocument: Screen<"LessonDocument"> = ({ route, navigation }) => {
const theme = useTheme();
Expand Down

0 comments on commit e5533c5

Please sign in to comment.