journal

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateTotalTime

func CalculateTotalTime(entries []JournalEntry) (time.Duration, error)

CalculateTotalTime calculates the total time duration for a slice of JournalEntry. It iterates over each entry in the slice and checks if the end time of the entry is after the start time. If the end time is not after the start time, it returns an error indicating that the entry is invalid. Otherwise, it adds the difference between the end time and the start time to the total duration. After iterating over all entries, it returns the total duration and nil. If there are no entries in the slice, it returns a duration of 0 and nil.

func SaveEntries

func SaveEntries(journalEntries []JournalEntry, filename string) error

SaveEntries encodes the given journal entries into JSON format and writes them to a file with the specified filename.

The function will return an error if the encoding process fails or if the file cannot be created or written to.

The function takes two parameters: - journalEntries: a slice of JournalEntry objects to be saved. - filename: a string representing the name of the file to write to.

Example:

entries := []JournalEntry{...}
err := SaveEntries(entries, "journal.json")
if err != nil {
    log.Fatal(err)
}

Types

type JournalEntry

type JournalEntry struct {
	ID        string
	StartTime time.Time
	EndTime   time.Time
	Notes     []Note
}

func FetchEntriesByMonthDate

func FetchEntriesByMonthDate(journalEntries []JournalEntry, filterDate time.Time) ([]JournalEntry, error)

FetchEntriesByMonthDate filters a slice of JournalEntry objects and returns a new slice containing only the entries from the given date's month. The function uses the Year() and Month() functions from time standard library

The function takes a slice of JournalEntry objects and iterates over each entry. It checks the start time of each entry and compares it with the current month. If the entry belongs to the current month, it is added to the new slice.

If no entries are passed, or no entries belong to the current month, the function returns an error along with an empty slice.

Example:

entries := []JournalEntry{...}
currentMonthEntries, err := FetchEntriesByMonthDate(entries)
if err != nil {
    log.Fatal(err)
}
fmt.Println(currentMonthEntries) // Prints the entries for the current week

func FetchEntriesByWeekDate

func FetchEntriesByWeekDate(journalEntries []JournalEntry, currentDate time.Time) ([]JournalEntry, error)

FetchEntriesByWeekDate filters a slice of JournalEntry objects and returns a new slice containing only the entries from the given date's week. The function uses the ISO week date system, where weeks start on a Monday and the first week of the year is the one that includes at least four days of the new year.

The function takes a slice of JournalEntry objects and iterates over each entry. It checks the start time of each entry and compares it with the current week. If the entry belongs to the current week, it is added to the new slice.

If no entries are passed, or no entries belong to the current week, the function returns an error along with an empty slice.

Example:

entries := []JournalEntry{...}
currentWeekEntries, err := FetchEntriesByWeekDate(entries)
if err != nil {
    log.Fatal(err)
}
fmt.Println(currentWeekEntries) // Prints the entries for the current week

func FetchEntryByID

func FetchEntryByID(id string, entries []JournalEntry) (*JournalEntry, int)

FetchEntryByID searches for a JournalEntry in the provided slice of entries by its ID. It returns a pointer to the found JournalEntry and its index in the slice If the entry is not found, it returns nil and -1.

func LoadEntries

func LoadEntries(filename string) ([]JournalEntry, error)

LoadEntries reads the JSON file with the given filename, unmarshals its contents into a slice of JournalEntry, and returns the slice. If the file does not exists, LoadEntries creates the file and returns an empty slice. If the file cannot be created, LoadEntries returns an error.

func NewJournalEntry

func NewJournalEntry() *JournalEntry

func (*JournalEntry) AddNote

func (j *JournalEntry) AddNote(note Note) error

func (*JournalEntry) EndDay

func (j *JournalEntry) EndDay()

func (*JournalEntry) String

func (j *JournalEntry) String() string

type Note

type Note struct {
	Contents string   `json:"Contents"`       // Note contents
	Tags     []string `json:"Tags,omitempty"` // Tags for this particular note
}

func (*Note) String

func (n *Note) String() string

Jump to

Keyboard shortcuts

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