diff --git a/docs/_sidebar.md b/docs/_sidebar.md index aa27f03..237dc72 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -21,6 +21,7 @@ - [Calculate Duration](./guide/calculateDuration.md) - [Mental Health Management](./guide/mentalHealth.md) - [Focus Time Management](./guide/focusTimeManagement.md) +- [Water Intake Reminder](./guide/waterIntakeReminder.md) diff --git a/docs/guide/focusTimeManagement.md b/docs/guide/focusTimeManagement.md index 9a4bcdb..7a6e1f7 100644 --- a/docs/guide/focusTimeManagement.md +++ b/docs/guide/focusTimeManagement.md @@ -42,7 +42,7 @@ console.log(schedule); ## Parameters -- focusUserPreferences(object): The date string in ISO format. +- focusUserPreferences(object): User inputs. ## Returns diff --git a/docs/guide/mentalHealth.md b/docs/guide/mentalHealth.md index def2521..6b255eb 100644 --- a/docs/guide/mentalHealth.md +++ b/docs/guide/mentalHealth.md @@ -49,8 +49,4 @@ console.log(dailySchedule); ## Parameters -- userPreferences(object): The date string in ISO format. - -## Returns - -- (object): As a result. +- userPreferences(object): User inputs diff --git a/docs/guide/waterIntakeReminder.md b/docs/guide/waterIntakeReminder.md new file mode 100644 index 0000000..a630827 --- /dev/null +++ b/docs/guide/waterIntakeReminder.md @@ -0,0 +1,42 @@ +# Water Intake Reminder. + +## Description + +This function helps users build a consistent water intake routine, boosting physical well-being during work hours. Each reminder will prompt them to stay hydrated throughout their day, supporting overall health and focus. + +## Usage + +```javascript +import { waterIntakeReminder } from 'world-clockify'; + +const preference = { + wakeUpTime: '08:00', + sleepTime: '12:00', + preferredTimeZone: 'America/New_York', + intakeInterval: 60, +}; + +const waterIntake = waterIntakeReminder(preference); + +console.log(waterIntake); +``` + +## Expected Output + +```bash +{ + 'Drink water at 09:30 am', + 'Drink water at 10:00 am', + 'Drink water at 10:30 am', + 'Drink water at 11:00 am', +} + +``` + +## Parameters + +- waterUserPreference(object): User inputs. + +## Returns + +- (object): As a result. diff --git a/src/function.ts b/src/function.ts index e1b5cb3..bce4f78 100644 --- a/src/function.ts +++ b/src/function.ts @@ -272,7 +272,7 @@ export const sheduleWorkAndBreaks = (preference: UserPreferences) => { const workSession = []; const breakTime = []; if (!IANAZone.isValidZone(preferredTimeZone)) { - throw Error( + throw new Error( `Invalid timezone: "${preferredTimeZone}". Please provide a valid IANA timezone (e.g., 'America/New_York').`, ); } @@ -343,3 +343,37 @@ export const focusTimeManager = (preference: focusUserPreferences) => { reminders: ['Time to focus!', 'Take a short break!', 'Focus time starts again soon!'], }; }; + +interface waterUserPreference { + wakeUpTime: string; + sleepTime: string; + preferredTimeZone: string; + intakeInterval: number; +} + +/** + * daily reminder for hydration that tracks when the user should drink water based on intervals + * @param preference- User preference + */ +export const waterIntakeReminder = (preference: waterUserPreference) => { + const { wakeUpTime, sleepTime, preferredTimeZone, intakeInterval } = preference; + + const reminders = []; + + if (!IANAZone.isValidZone(preferredTimeZone)) { + throw new Error( + `Invalid timezone: "${preferredTimeZone}". Please provide a valid IANA timezone (e.g., 'America/New_York').`, + ); + } + + let currentTime = DateTime.fromFormat(wakeUpTime, 'HH:mm', { zone: preferredTimeZone }); + const sleepDateTime = DateTime.fromFormat(sleepTime, 'HH:mm', { zone: preferredTimeZone }); + + while (currentTime < sleepDateTime) { + const nextReminder = currentTime.plus({ minutes: intakeInterval }); + reminders.push(`Drink water at ${nextReminder.toFormat('hh:mm a')}`); + currentTime = nextReminder; + } + + return reminders; +}; diff --git a/tests/index.test.ts b/tests/index.test.ts index 9eaf97f..7947800 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -12,6 +12,7 @@ import { getCountdownToEvent, sheduleWorkAndBreaks, focusTimeManager, + waterIntakeReminder, } from '../src/function.js'; describe('Timezone-Aware Date Helper', () => { @@ -150,4 +151,25 @@ describe('Timezone-Aware Date Helper', () => { end: '09:50 AM', }); }); + + it('should remind to drink water', () => { + const preference = { + wakeUpTime: '08:00', + sleepTime: '12:00', + preferredTimeZone: 'America/New_York', + intakeInterval: 60, + }; + + const waterIntake = waterIntakeReminder(preference); + + // Expected reminders at hourly intervals from 8:00 AM to 12:00 PM + const expectedReminders = [ + 'Drink water at 09:00 AM', + 'Drink water at 10:00 AM', + 'Drink water at 11:00 AM', + 'Drink water at 12:00 PM', + ]; + + expect(waterIntake).toEqual(expectedReminders); + }); });