settings

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(projectName string, hourlyRate float64) error

Create creates a new Config populated with projectName and hourlyRate and writes it to a ".tmporc" file in the current working directory ("./.tmporc"). If a ".tmporc" file already exists, Create returns an error and does not overwrite it. Any error encountered while saving the configuration is returned to the caller.

func CreateWithTemplate

func CreateWithTemplate(projectName string, hourlyRate float64, description string) error

CreateWithTemplate creates a new .tmporc file with a user-friendly format that includes all fields (even if empty) and helpful comments. This provides a better user experience by showing all available configuration options.

func FormatDate

func FormatDate(t time.Time) string

FormatDate formats a date according to the user's global date format preference. Returns date in MM/DD/YYYY, DD/MM/YYYY, or YYYY-MM-DD format based on config.

func FormatDateDashed

func FormatDateDashed(t time.Time) string

FormatDateDashed formats a date with dashes according to the user's date format preference. Returns date in MM-DD-YYYY, DD-MM-YYYY, or YYYY-MM-DD format based on config.

func FormatDateLong

func FormatDateLong(t time.Time) string

FormatDateLong formats a date in a long human-readable format. Returns date as "Mon, Jan 2, 2006" regardless of user preferences (for headers).

func FormatDateTime

func FormatDateTime(t time.Time) string

FormatDateTime formats a date and time according to the user's global preferences. Returns combined date and time string (e.g., "01/02/2006 3:04 PM" or "2006-01-02 15:04").

func FormatDateTimeDashed

func FormatDateTimeDashed(t time.Time) string

FormatDateTimeDashed formats a date and time with dashes according to preferences. Returns combined date and time string (e.g., "01-02-2006 3:04 PM" or "2006-01-02 15:04").

func FormatDateTimeLong

func FormatDateTimeLong(t time.Time) string

FormatDateTimeLong formats a date and time in a long human-readable format. Returns "Jan 2, 2006 at 3:04 PM" or "Jan 2, 2006 at 15:04" based on time preference.

func FormatTime

func FormatTime(t time.Time) string

FormatTime formats a time according to the user's global time format preference. Returns time in either 24-hour format (15:04) or 12-hour format (3:04 PM).

func FormatTimePadded

func FormatTimePadded(t time.Time) string

FormatTimePadded formats a time with zero-padded hours according to the user's time format preference. Returns time in either 24-hour format (15:04) or 12-hour format (03:04 PM).

func GetGlobalConfigPath

func GetGlobalConfigPath() (string, error)

GetGlobalConfigPath returns the absolute path to the global configuration file. The config is stored at $HOME/.tmpo/config.yaml alongside the database. If the TMPO_DEV environment variable is set to "1" or "true", uses $HOME/.tmpo-dev/config.yaml. Returns an error if the home directory cannot be determined.

Types

type Config

type Config struct {
	ProjectName string  `yaml:"project_name"`
	HourlyRate  float64 `yaml:"hourly_rate,omitempty"`
	Description string  `yaml:"description,omitempty"`
}

Config represents the project's configuration as loaded from a YAML file. It contains identifying and billing information along with an optional description.

ProjectName is the human-readable name of the project. HourlyRate is the billable hourly rate for the project; when zero it will be omitted from YAML. Description is an optional free-form description of the project; when empty it will be omitted from YAML.

! IMPORTANT When adding new fields to this struct, also update configTemplate below. !

func FindAndLoad

func FindAndLoad() (*Config, string, error)

FindAndLoad searches upward from the current working directory for a file named ".tmporc". Starting at os.Getwd(), it ascends parent directories until it either finds the file or reaches the filesystem root.

If a ".tmporc" file is found, FindAndLoad calls Load(path) and returns the resulting *Config, the absolute path to the discovered file, and any error returned by Load. If Load returns an error the returned *Config may be nil.

If the current working directory cannot be determined, or if no ".tmporc" is found before reaching the root, FindAndLoad returns (nil, "", err) describing the failure.

func Load

func Load(path string) (*Config, error)

Load reads a YAML configuration file from the provided path and unmarshals it into a Config. It returns a pointer to the populated Config on success. If the file cannot be read or the contents cannot be parsed as YAML, Load returns a wrapped error describing the failure.

func (*Config) Save

func (c *Config) Save(path string) error

Save marshals the Config into YAML and writes it to the provided filesystem path. The configuration is encoded using yaml.Marshal and written with file mode 0644. If a file already exists at path it will be overwritten. An error is returned if marshaling fails or if writing the file to disk is unsuccessful.

type GlobalConfig

type GlobalConfig struct {
	Currency   string `yaml:"currency"`
	DateFormat string `yaml:"date_format,omitempty"`
	TimeFormat string `yaml:"time_format,omitempty"`
	Timezone   string `yaml:"timezone,omitempty"`
}

GlobalConfig represents the user's global configuration as loaded from a YAML file. It contains user-wide settings that apply across all projects.

Currency is the ISO 4217 currency code (e.g., USD, EUR, GBP) for billing display. DateFormat is the preferred date format (e.g., MM/DD/YYYY, DD/MM/YYYY, YYYY-MM-DD). TimeFormat is the preferred time format (e.g., 24-hour, 12-hour). Timezone is an optional IANA timezone name (e.g., America/New_York, UTC).

func DefaultGlobalConfig

func DefaultGlobalConfig() *GlobalConfig

DefaultGlobalConfig returns a GlobalConfig with sensible default values. Currency defaults to USD, while DateFormat, TimeFormat, and Timezone are empty (meaning the system will use defaults and local timezone respectively).

func LoadGlobalConfig

func LoadGlobalConfig() (*GlobalConfig, error)

LoadGlobalConfig loads the global configuration from ~/.tmpo/config.yaml (or ~/.tmpo-dev/config.yaml if TMPO_DEV is set). If the file doesn't exist, it returns a default configuration without error. If the file exists but cannot be read or parsed, it returns an error.

func (*GlobalConfig) Save

func (gc *GlobalConfig) Save() error

Save writes the GlobalConfig to ~/.tmpo/config.yaml (or ~/.tmpo-dev/config.yaml if TMPO_DEV is set). It creates the directory if it doesn't exist. Returns an error if the directory cannot be created or the file cannot be written.

Jump to

Keyboard shortcuts

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