Documentation ¶
Index ¶
- Variables
- func CalcOvertime(workStart string, workEnd string) int
- func GetVersion()
- func PreviousYearRecordsExist() bool
- func SaveConfig(configPath string, conf Configuration) error
- func Status(recordList []TimeRecord) string
- func ValidateCSVFile(filepath string) error
- func WriteRecords(recordFileName string, recordList []TimeRecord)
- type Configuration
- type TimeRecord
- func ClockIn(workStart ...string) TimeRecord
- func ClockOut(openRecord TimeRecord, workEnd ...string) TimeRecord
- func In(recordList []TimeRecord, args []string) []TimeRecord
- func Out(recordList []TimeRecord, args []string) []TimeRecord
- func ReadRecords(recordFileName string) []TimeRecord
- func Summary(recordList []TimeRecord) []TimeRecord
- func Take(recordList []TimeRecord) []TimeRecord
Constants ¶
This section is empty.
Variables ¶
var SoftwareVersion = 0.5
Functions ¶
func CalcOvertime ¶
CalcOvertime calculates the overtime in minutes based on the given work start and end times. It takes the work start and end times as strings in the format "hh:mm", and uses the default working hours and break time from the config file to calculate the overtime. It returns the overtime in minutes as an integer.
func GetVersion ¶
func GetVersion()
GetVersion prints the current software version and checks for updates. It also prints the latest version available and informs the user if a new update is available.
func PreviousYearRecordsExist ¶
func PreviousYearRecordsExist() bool
func SaveConfig ¶
func SaveConfig(configPath string, conf Configuration) error
func Status ¶
func Status(recordList []TimeRecord) string
Status returns a string containing information about the user's current work status.
Parameters: - recordList: A list of TimeRecord structs representing the user's past working time times.
Returns: A formatted string containing the clock-in time and overtime minutes.
func ValidateCSVFile ¶
ValidateCSVFile validates a CSV file at the given filepath against the expected format of the time tracker application. The CSV file should have the following columns: type, date (YYYY-MM-DD), start time (HH:MM), end time (HH:MM), and overtime (minutes). The function returns an error if the file is not valid, and nil if it is valid.
func WriteRecords ¶
func WriteRecords(recordFileName string, recordList []TimeRecord)
Types ¶
type Configuration ¶
type Configuration struct { InitialOvertime int DefaultWorkingHours int BreakTime int StorageLocation string }
func LoadConfig ¶
func LoadConfig(configPath string) Configuration
LoadConfig reads a JSON configuration file from the given path and returns a Configuration struct. If the file cannot be opened or decoded, it returns an empty Configuration struct. The function takes a single parameter, `configPath`, which is the path to the JSON configuration file.
type TimeRecord ¶
type TimeRecord struct { RecordType string Date time.Time WorkStart string WorkEnd string MinutesOvertime int }
func ClockIn ¶
func ClockIn(workStart ...string) TimeRecord
ClockIn creates a new TimeRecord with a record type of "R", a date of the current date, and a work start time of either the current time or the provided work start time (if present). The work end time is empty and the minutes of overtime is initialized to 0. Returns the new TimeRecord.
func ClockOut ¶
func ClockOut(openRecord TimeRecord, workEnd ...string) TimeRecord
ClockOut updates the provided TimeRecord with a work end time of either the provided time or the current time (if not provided), calculates the minutes of overtime worked, and returns the updated TimeRecord.
func In ¶
func In(recordList []TimeRecord, args []string) []TimeRecord
In function is used to clock in a new time record with the current time. If an argument is provided, it will be used as the work start time for the new record.
func Out ¶
func Out(recordList []TimeRecord, args []string) []TimeRecord
Out clocks the user out and adds a new time record to the input recordList.
Parameters: - recordList: A list of TimeRecord structs representing the user's past working time times. - args: A slice of strings containing the command-line arguments passed to the program.
Returns: The input recordList, with a new TimeRecord appended if the user was clocked out successfully.
func ReadRecords ¶
func ReadRecords(recordFileName string) []TimeRecord
func Summary ¶
func Summary(recordList []TimeRecord) []TimeRecord
Summary prints a summary of the user's overtime hours based on the given list of time records.
Parameters: - recordList: A list of TimeRecord structs representing the user's past working time times.
Returns: The input recordList, unchanged.
func Take ¶
func Take(recordList []TimeRecord) []TimeRecord
Take adds a new TimeRecord to the given list indicating that the user is taking time off.
Parameters: - recordList: A list of TimeRecord structs representing the user's past working time times.
Returns: A new list of TimeRecord structs that includes the new TimeRecord representing the time off.