Documentation ¶
Index ¶
- type Calendar
- type CalendarApi
- type Date
- type Day
- type EMailPublisher
- type ExcelReportFormatter
- func (formatter *ExcelReportFormatter) FileExtension() string
- func (formatter *ExcelReportFormatter) WithHolidays(holidays []Holiday)
- func (formatter *ExcelReportFormatter) WriteMonthlyReportToBuffer(report *MonthlyReport) (*bytes.Buffer, error)
- func (formatter *ExcelReportFormatter) WriteMonthlyReportToFile(report *MonthlyReport, filename string) error
- type FilePublisher
- type Holiday
- type LocaLRepository
- func (repo *LocaLRepository) Add(record TimeTrackingRecord) (TimeTrackingRecord, error)
- func (repo *LocaLRepository) Capture(deviceId string, recordType RecordType) error
- func (repo *LocaLRepository) Captured(deviceId string, recordType RecordType, timestamp time.Time) error
- func (repo *LocaLRepository) Delete(key string) error
- func (repo *LocaLRepository) ListRecords(deviceId string, start time.Time, end time.Time) ([]TimeTrackingRecord, error)
- type Locale
- type MonthlyReport
- type RecordType
- type ReportCalculator
- type ReportCalulator
- type ReportFormatter
- type ReportPublisher
- type S3Publisher
- type S3Repository
- func (repo *S3Repository) Add(record TimeTrackingRecord) (TimeTrackingRecord, error)
- func (repo *S3Repository) Capture(deviceId string, recordType RecordType) error
- func (repo *S3Repository) Captured(deviceId string, recordType RecordType, timestamp time.Time) error
- func (repo *S3Repository) Delete(key string) error
- func (repo *S3Repository) ListRecords(deviceId string, start time.Time, end time.Time) ([]TimeTrackingRecord, error)
- type TimeTracker
- type TimeTrackingRecord
- type TimeTrackingRecordManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Calendar ¶
type Calendar interface { // GetHolidays returns a list of holiday for given year and month. GetHolidays(int, int) ([]Holiday, error) }
Calendar is used to get holidays or non-working days.
type CalendarApi ¶
type CalendarApi struct {
// contains filtered or unexported fields
}
CalendarApi is used to retrieve holidays from an online service.
func NewCalendarApi ¶ added in v1.1.0
func NewCalendarApi(apiKey string, location Locale) *CalendarApi
newCalendarApi returns a new api to get holidays.
func (*CalendarApi) GetHolidays ¶
func (api *CalendarApi) GetHolidays(year, month int) ([]Holiday, error)
GetHolidays try to fetch holidays for given month.
type Date ¶
type Date struct { // Year this date belongs to. Year int // Month this date belongs to. Month int // Day this date belongs to. Day int }
Date is a single calendar day.
type Day ¶
type Day struct { // Date of this day. Date // Type of a time tracking event. Type RecordType // WorkingTime is the total time of work for a day. WorkingTime time.Duration // BreakTime is total time of breaks for a day. BreakTime time.Duration // Events is a list of captured time tracking events. Events []TimeTrackingRecord }
Day is a single day of working, illness or vacations. It contains all time tracking events occurred for this date and calculated working/break time based on this events.
type EMailPublisher ¶ added in v1.3.0
type EMailPublisher struct {
Source, Destination, Subject, Message string
}
EMailPublisher delivers time tracking reports via email.
func NewEMailPublisher ¶ added in v1.3.0
func NewEMailPublisher(source, destination, subject, message string) *EMailPublisher
NewEMailPublisher creates a new publsher to send time tracking reports via email.
type ExcelReportFormatter ¶
type ExcelReportFormatter struct {
// contains filtered or unexported fields
}
ExcelReportFormatter will generate Excel files for reports
func NewExcelReportFormatter ¶
func NewExcelReportFormatter(logger log.Logger) *ExcelReportFormatter
NewExcelReportFormatter returns a new formatter to generate an excel file for a report.
func (*ExcelReportFormatter) FileExtension ¶ added in v1.1.0
func (formatter *ExcelReportFormatter) FileExtension() string
FileExtension reurns file extension for Exce files: xlsx.
func (*ExcelReportFormatter) WithHolidays ¶
func (formatter *ExcelReportFormatter) WithHolidays(holidays []Holiday)
WithHolidays will assign give list of holidays for output formatting.
func (*ExcelReportFormatter) WriteMonthlyReportToBuffer ¶
func (formatter *ExcelReportFormatter) WriteMonthlyReportToBuffer(report *MonthlyReport) (*bytes.Buffer, error)
WriteMonthlyReportToBuffer returns a buffer for gemerated report output.
func (*ExcelReportFormatter) WriteMonthlyReportToFile ¶
func (formatter *ExcelReportFormatter) WriteMonthlyReportToFile(report *MonthlyReport, filename string) error
WriteMonthlyReportToFile will generate a report outout an writes it to given file.
type FilePublisher ¶ added in v1.1.0
type FilePublisher struct { FileMode os.FileMode Path string // contains filtered or unexported fields }
FilePublisher wirtes contents to files.
func NewFilePublisher ¶ added in v1.1.0
func NewFilePublisher(path *string, logger log.Logger) *FilePublisher
NewFilePublisher returns a new publisher which writes report content to files.
type Holiday ¶
type Holiday struct { // Date of this day. Date // Description of a public holiday. Description string }
Holiday is a single, public holiday.
type LocaLRepository ¶
type LocaLRepository struct {
Records map[string]map[Date][]TimeTrackingRecord
}
LocaLRepository is an in memory time tracker.
func NewLocaLRepository ¶
func NewLocaLRepository() *LocaLRepository
NewLocaLRepository create a new, in menory, time tracker.
func (*LocaLRepository) Add ¶ added in v1.4.0
func (repo *LocaLRepository) Add(record TimeTrackingRecord) (TimeTrackingRecord, error)
Add creates a new time tracking record with given values. Same time tacking record will be returned together with a generated key.
func (*LocaLRepository) Capture ¶
func (repo *LocaLRepository) Capture(deviceId string, recordType RecordType) error
Capture will create a time tracking record with passed type at time this method has been called.
func (*LocaLRepository) Captured ¶
func (repo *LocaLRepository) Captured(deviceId string, recordType RecordType, timestamp time.Time) error
Captured creates a time tracking record for passed point in time.
func (*LocaLRepository) Delete ¶ added in v1.4.0
func (repo *LocaLRepository) Delete(key string) error
Delete will remove given time tracking record.
func (*LocaLRepository) ListRecords ¶
func (repo *LocaLRepository) ListRecords(deviceId string, start time.Time, end time.Time) ([]TimeTrackingRecord, error)
ListRecords returns available time tracking records for given range.
type Locale ¶
type Locale struct { // ISO 3166-1 country code. Country string // Timezone, used to format time in reports. Timezone *string // DateFormat, used tp write dates in given format to report outputs. DateFormat *string // DefaultWorkTime is used if there's no end of work for a day, including breaks. DefaultWorkTime time.Duration // Breaks is a map of working durations and breaks which have to be applied for this time. Breaks map[time.Duration]time.Duration }
Locale contains settings like country, region, time zone and working breaks.
type MonthlyReport ¶
type MonthlyReport struct { // Year this report belongs to. Year int // Month this reprt has been created for. Month int // Location a report should be generated for. Location Locale // Days is the list of days in a momth. Days []Day // TotalWorkingTine is the entire working time of a month. TotalWorkingTime time.Duration }
MonthlyReport included total amount of work for a month and details about each single day.
type RecordType ¶
type RecordType string
RecordType defines with kind of event has been tracked.
const ( // WORKDAY is used to track start and end of a usual workday. WORKDAY RecordType = "workday" // ILLNESS is used to track sick leave. ILLNESS RecordType = "illness" // VACATION to track holiday absence. VACATION RecordType = "vacation" // WEEKEND used for non-working days in a week. WEEKEND RecordType = "weekend" )
type ReportCalculator ¶
type ReportCalculator interface { // WithTimeTrackingRecords applies a list of reords for report calculation. WithTimeTrackingRecords([]TimeTrackingRecord) // MonthlyReport calculates a report for given year and month. MonthlyReport(int, int, RecordType) (*MonthlyReport, error) }
ReportCalculator creates a time tracking summary based on captured records.
type ReportCalulator ¶
type ReportCalulator struct {
// contains filtered or unexported fields
}
ReportCalulator calulates working and break time for all day given by time tracking records.
func NewReportCalulator ¶
func NewReportCalulator(records []TimeTrackingRecord, location Locale) *ReportCalulator
NewReportCalulator returns a new calulator using given time tracking records and local.
func (*ReportCalulator) MonthlyReport ¶
func (calculator *ReportCalulator) MonthlyReport(year, month int, latestType RecordType) (*MonthlyReport, error)
MonthlyReport generates a report for given year and month from existing time tracking records.
func (*ReportCalulator) WithTimeTrackingRecords ¶ added in v1.0.4
func (calculator *ReportCalulator) WithTimeTrackingRecords(records []TimeTrackingRecord)
WithTimeTrackingRecords will apply given records for calculation.
type ReportFormatter ¶
type ReportFormatter interface { // WithHolidays will assign give list of holidays for output formatting. WithHolidays(holidays []Holiday) // WriteMonthlyReportToFile will generate a report outout an writes it to given file. WriteMonthlyReportToFile(*MonthlyReport, string) error // WriteMonthlyReportToBuffer returns a buffer for gemerated report output. WriteMonthlyReportToBuffer(*MonthlyReport) (*bytes.Buffer, error) // FileExtension returns an extenstion for a report file. FileExtension() string }
ReportFormatter generates an output for passed reports.
type ReportPublisher ¶
type ReportPublisher interface { // Send publishes given report data to a target. Send([]byte, string) error }
ReportPublisher sends given report to a defined target.
type S3Publisher ¶
type S3Publisher struct {
// contains filtered or unexported fields
}
S3Publisher uploads given report to an AWS S3 bucket.
func NewS3Publisher ¶
func NewS3Publisher(awsRegion, bucket, basePath *string, logger log.Logger) *S3Publisher
NewS3Publisher returns a new publisher to upload reports to AWS S3.
type S3Repository ¶
type S3Repository struct {
// contains filtered or unexported fields
}
S3Repository uses AWS S3 bucket to persist time tracking records.
func NewS3Repository ¶
func NewS3Repository(awsRegion, bucket, basePath *string) *S3Repository
NewS3Repository create a new repository to store time tracking records in AWS S3.
func (*S3Repository) Add ¶ added in v1.4.0
func (repo *S3Repository) Add(record TimeTrackingRecord) (TimeTrackingRecord, error)
Add creates a new time tracking record with given values. Same time tacking record will be returned together with a generated key.
func (*S3Repository) Capture ¶
func (repo *S3Repository) Capture(deviceId string, recordType RecordType) error
Capture will create a time tracking record with passed type at time this method has been called.
func (*S3Repository) Captured ¶
func (repo *S3Repository) Captured(deviceId string, recordType RecordType, timestamp time.Time) error
Captured creates a time tracking record for passed point in time.
func (*S3Repository) Delete ¶ added in v1.4.0
func (repo *S3Repository) Delete(key string) error
Delete will remove given time tracking record.
func (*S3Repository) ListRecords ¶
func (repo *S3Repository) ListRecords(deviceId string, start time.Time, end time.Time) ([]TimeTrackingRecord, error)
ListRecords returns all records captured for given device id and time range.
type TimeTracker ¶
type TimeTracker interface { // Capture will create a time tracking record with passed type at time this method has been called. Capture(string, RecordType) error // Captured creates a time tracking record for passed point in time. Captured(string, RecordType, time.Time) error // ListRecords returns available time tracking records for given range. ListRecords(string, time.Time, time.Time) ([]TimeTrackingRecord, error) }
TimeTracker is used to persist event, e.g start/end of a workday, illness and vacations. All timestamps are collected in UTC.
type TimeTrackingRecord ¶
type TimeTrackingRecord struct { // Key is an unique identifier of a time tracking record. Key string // DeviceId is an identifier of a device which captures a time tracking record. DeviceId string // Type of a time tracking event. Type RecordType // Timestamp is the point in time a time tracking event has occurred. Timestamp time.Time // Estimated time tracking report a used to fill missing events. e.g. workday end if it not has been captured. Estimated bool }
TimeTrackingReport os a single captured time tracking event.
type TimeTrackingRecordManager ¶ added in v1.4.0
type TimeTrackingRecordManager interface { // Add creates a new time tracking record with given values. Same time tacking record will be // returned together with a generated key. Add(TimeTrackingRecord) (TimeTrackingRecord, error) // Delete will remove time tracking record by passed key. Delete(string) error }
TimeTrackingRecordManager is used to create, update or delete single time tracking records.