export

package
v0.1.4-beta1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToCSV

func ToCSV(entries []*storage.TimeEntry, filename string) error

ToCSV writes the provided slice of time entries to a CSV file at the given filename. The file is created (or truncated if it already exists) and a CSV writer is used to emit a header row followed by one record per entry.

The CSV contains the following columns in order:

  • "Project" : entry.ProjectName
  • "Start Time" : entry.StartTime formatted as "2006-01-02 15:04:05"
  • "End Time" : entry.EndTime formatted as "2006-01-02 15:04:05" or an empty string if EndTime is nil
  • "Duration (hours)" : entry.Duration() expressed in hours, formatted with two decimal places
  • "Description" : entry.Description

The function returns an error if the file cannot be created or if writing any header/record fails. The CSV writer is flushed before returning, and the file is closed via deferred cleanup. The caller should ensure the provided filename is writable.

func ToJson

func ToJson(entries []*storage.TimeEntry, filename string) error

ToJson writes the given time entries to filename in pretty-printed JSON. Each storage.TimeEntry is converted to an ExportEntry with these mappings:

  • Project: entry.ProjectName
  • StartTime: formatted using layout "2006-01-02T15:04:05Z07:00" (RFC3339-like)
  • EndTime: formatted using the same layout if entry.EndTime is non-nil; omitted otherwise
  • Duration: entry.Duration().Hours() (floating-point hours)
  • Description: entry.Description

The function creates or truncates the target file, encodes the slice of ExportEntry values with json.Encoder and indentation, and closes the file before returning. It returns an error if the file cannot be created or if JSON encoding fails. Callers must ensure the destination path is writable.

Types

type ExportEntry

type ExportEntry struct {
	Project     string  `json:"project"`
	StartTime   string  `json:"start_time"`
	EndTime     string  `json:"end_time,omitempty"`
	Duration    float64 `json:"duration_hours"`
	Description string  `json:"description,omitempty"`
}

ExportEntry represents a single time-tracking record prepared for JSON export. It contains the project name, the start timestamp, an optional end timestamp, the duration expressed in hours, and an optional human-readable description.

Project is the associated project identifier or name. StartTime is the entry start timestamp as a string (for example, RFC3339). EndTime is the optional end timestamp; it will be omitted from JSON when empty. Duration is the total duration of the entry in hours as a floating-point value. Description is an optional text note; it will be omitted from JSON when empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL