Skip to content

Commit

Permalink
✨ Add date parameter to query entries specific date only
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahNxT committed May 22, 2024
1 parent 7a15007 commit 6f45ef5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,26 @@ Run the command to generate the timesheet for today:
npx timeshit list
```

## Generate Timesheet for a Custom Date Range
You can also specify a custom date range using the --startDate (-sd) and --endDate (-ed) options:
### Generate Timesheet for a Custom Date Range
You can specify a custom date range using the --startDate (-sd) and --endDate (-ed) options:
```bash
npx timeshit list --start-date YYYY-MM-DD --endDate YYYY-MM-DD
```

### Generate Timesheet for a Specific Date
You can specify a specific date using the --date (-d) option alone:
```bash
npx timeshit list --startDate YYYY-MM-DD --endDate YYYY-MM-DD
npx timeshit list --date YYYY-MM-DD
```

## Generate Timesheet for a Specific Date

## Generate Timesheet from a Date to Today
You can specify a custom date range using the --startDate (-sd) option alone:
```bash
You can also specify a specific date using the --startDate (-sd) option alone:

```bash
npx timeshit list --startDate YYYY-MM-DD
npx timeshit list --start-date YYYY-MM-DD
```

## Example Output
Expand Down Expand Up @@ -97,7 +105,7 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file

## Connect
- Follow me on Twitter: [@does_it_code](https://twitter.com/does_it_code)
- Connect with me on LinkedIn: [Noah Nxumalo](https://www.linkedin.com/in/noah-gillard/)
- Connect with me on LinkedIn: [Noah Gillard](https://www.linkedin.com/in/noah-gillard/)

Feel free to reach out with any questions or feedback! Enjoy using Toggl2Timeshit to simplify your timesheet generation.

27 changes: 14 additions & 13 deletions commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ const token = fs.readFileSync(filePath, "utf8");
const base64Credentials = Buffer.from(`${token}:api_token`).toString("base64");

const currTz = "Europe/Brussels";
const yesterday = dayjs()
.subtract(1, "days")
.tz(currTz)
.startOf("day")
.toISOString();
const today = dayjs().tz(currTz).startOf("day").toISOString();
const tomorrow = dayjs().add(1, "days").tz(currTz).startOf("day").toISOString();

Expand Down Expand Up @@ -99,20 +94,26 @@ async function selectWorkspaceId() {
}

export async function list(options) {
const { startDate, endDate } = options;
const { startDate, endDate, date } = options;

const workspaceId = await selectWorkspaceId();
if (!workspaceId) {
return;
}

// Use provided dates or default to today and tomorrow
const start = startDate
? dayjs(startDate).tz(currTz).startOf("day").toISOString()
: today;
const end = endDate
? dayjs(endDate).tz(currTz).startOf("day").toISOString()
: tomorrow;
// Determine the date range based on the provided options
let start, end;
if (date) {
start = dayjs(date).tz(currTz).startOf("day").toISOString();
end = dayjs(date).tz(currTz).add(1, "day").startOf("day").toISOString();
} else {
start = startDate
? dayjs(startDate).tz(currTz).startOf("day").toISOString()
: today;
end = endDate
? dayjs(endDate).tz(currTz).startOf("day").toISOString()
: tomorrow;
}

const timeEntriesUrl = `https://api.track.toggl.com/api/v9/me/time_entries?start_date=${start}&end_date=${end}`;
const timeEntriesJson = await fetchTimeEntries(timeEntriesUrl);
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ program
.command("list")
.option("-sd, --start-date <date>", "Start date for time entries YYYY-MM-DD")
.option("-ed, --end-date <date>", "End date for time entries YYYY-MM-DD")
.option("-d, --date <date>", "Date for time entries YYYY-MM-DD")
.description("List tracked time registries per project.")
.action(list);

Expand Down

0 comments on commit 6f45ef5

Please sign in to comment.