Skip to content

Add time entry, include start with create#165

Merged
beauraines merged 6 commits into
beauraines:mainfrom
benthayer:add-time-entry
May 25, 2024
Merged

Add time entry, include start with create#165
beauraines merged 6 commits into
beauraines:mainfrom
benthayer:add-time-entry

Conversation

@benthayer
Copy link
Copy Markdown
Contributor

Hello again,

I added the functionality to add entries with start/stop time.

Also there was a bug in the parseTime function. I fixed it so that time entries are correct for midnight and then I moved it into the utils file

@beauraines beauraines self-assigned this May 21, 2024
@beauraines
Copy link
Copy Markdown
Owner

@benthayer I've been traveling and am catching up. This is on my todo list, but it will be a few days before i get back to it.

@benthayer
Copy link
Copy Markdown
Contributor Author

@benthayer I've been traveling and am catching up. This is on my todo list, but it will be a few days before i get back to it.

All good, no rush. I'm using my local version, so no rush merging this in, just wanted to share my code

Comment thread cmds/addTimeEntry.mjs Outdated

const debug = debugClient('toggl-cli-add');

export const command = 'add <startTime> <endTime> <description>'
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think these should be optional using the [] syntax, so that the start, end and description arguments can be used, too.

This will give us more flexibility - I think about adding new entries like "I did xxx from start until end", but it wil work in the "From start to end, I did xxx"

I'll make that change and test - but I'm in the middle of making brunch and I discovered that I can push changes!

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

With the change in

this works

DEBUG=toggl-cli-add ./cli.js add -d foo -s 8:30 -e '9:02 AM'

as well as what you had originally

DEBUG=toggl-cli-add ./cli.js add 8:00 '08:33 AM' foo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great, glad we have functionality we both like!

Makes the positional `startTime`, `endTime` and `description` optional, so that they can _also_ be specified through cli options
Comment thread cmds/addTimeEntry.mjs
}
argv.description ? params.description = argv.description : undefined
debug(params)
const timeEntry = await client.timeEntries.create(params)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I have a createTimeEntry() in the utils, but it doesn't support creating a time entry with an endTime. I'll open a new issue to extend that function and use it here too. I see that you started with the edit command which does its own interaction with the client. I'm not very good about repeating myself or abstracting methods.

Comment thread utils.js
* @param {string} timeString timelike string e.g. 4:50PM '12:00 AM' etc.
* @returns {object} dayjs object
*/
export function parseTime (timeString) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you for moving this here, this really should have been available for reuse.

@beauraines beauraines merged commit d73f181 into beauraines:main May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants