Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the additional flags without formatting #35

Conversation

MaximilianSoerenPollak
Copy link

2nd attempt at the PR. Comment from old one:

Added both hours and date to both export types.
Choose the 'string' datatype as that makes it easiest to fit in the way the project is structured.

date -> 'DD-MM-YY' -> '03-04-2020'
hours -> 3.45 # uses the 'fmtHours' function
Both flags are optional and by default disabled.

Build successfully with 'make VERSION=0.0.8' and tested both outputs with the optional flags. -> Output as desired.

Let me know if any other changes are requiered or wanted, and I adapt as needed.

This should close #32

@MaximilianSoerenPollak
Copy link
Author

Nope.. it does not let me push the code without it completly formatting. I'm sorry. I can't then do a PR.

My apologies.

If you still want to see the changes and commit them yourself you can view the PR by 'ignorign Whitespace' in the GIthub viewer.
Or just copy the code underneath.

-> Define hours & date argument variables
rootCmd.go

//...
var exportHours bool 
var exportDate bool 
//...

-> Add Date & Hours to the entry struct
-> Add 'SetDateFromBegin' function

entry.go

type Entry struct {
//...
Date string `json:"date,omitempty"`
Hours string`json:"hours,omitempty"`
//...
}

func (entry *Entry) SetDateFromBegin() {
entry.Date = entry.Begin.Format("02-03-2006") // DD-MM-YYYY
} 

-> Add hours & dates to the arguments
-> Add addtional information to the output if wanted

exportCmd.go

//...
if exportHours || exportDate {
	var addedInformationEntries []Entry
	for _, v := range filteredEntries {
		if exportHours {
			v.Hours = fmtHours(v.GetDuration())
		}
		if exportDate {
			v.SetDateFromBegining()
		}
		addedInformationEntries = append(addedInformationEntries, v)
	}
	// Reasignment here so we don't need to check other flags later
	filteredEntries = addedInformationEntries
}
//...
exportCmd.Flags().BoolVar(&exportDate, "date", false, "Add the 'date' field to the export")
exportCmd.Flags().BoolVar(&exportHours, "hours-decimal", false, "Add an 'hours' field calculated with '--decimal' to the export")
//...

And lastly in tyme.go add the 'Hours & Date` to the struct & the intialisation.

I hope this helps at bit at least.

@MaximilianSoerenPollak MaximilianSoerenPollak deleted the addHoursAndDateAsOptionalFlags branch July 25, 2024 09:51
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.

[FEATURE] Adding an optional 'date' & 'hours' field to the 'zeit export' command.
1 participant