Skip to content

Commit

Permalink
feat(user): water intake reminder (#36)
Browse files Browse the repository at this point in the history
* feat: water intake reminder

* fix: sidebar for water reminder
  • Loading branch information
shivam-sharma7 authored Oct 26, 2024
1 parent 2d7f986 commit a91a230
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

</details>

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/focusTimeManagement.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ console.log(schedule);
## Parameters
- focusUserPreferences(object): The date string in ISO format.
- focusUserPreferences(object): User inputs.
## Returns
Expand Down
6 changes: 1 addition & 5 deletions docs/guide/mentalHealth.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
42 changes: 42 additions & 0 deletions docs/guide/waterIntakeReminder.md
Original file line number Diff line number Diff line change
@@ -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.
36 changes: 35 additions & 1 deletion src/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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').`,
);
}
Expand Down Expand Up @@ -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;
};
22 changes: 22 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getCountdownToEvent,
sheduleWorkAndBreaks,
focusTimeManager,
waterIntakeReminder,
} from '../src/function.js';

describe('Timezone-Aware Date Helper', () => {
Expand Down Expand Up @@ -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);
});
});

0 comments on commit a91a230

Please sign in to comment.