at

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Base URL for AutoTask.
	URI_AUTOTASK = "https://www.autotask.net"

	// Format string for ticket detail URL, expects the base URL and ticketID.
	URI_TICKET_DETAIL = "%s/Mvc/ServiceDesk/TicketDetail.mvc?ticketID=%d"

	// Format string for task detail URL, expects the base URL and taskID.
	URI_TASK_DETAIL = "%s/Mvc/Projects/TaskDetail.mvc?taskID=%d"

	// Suffix for the landing URL, used for waiting.
	URI_LANDING_SUFFIX = "/Mvc/Framework/Navigation.mvc/Landing"

	// Format string for the landing URL, expects the base URL.
	URI_LANDING = "%s/" + URI_LANDING_SUFFIX
)

Constants for specific AutoTask URIs.

Variables

BaseURL is the default base URL for AutoTask operations.

Functions

func Date

func Date(year int, month time.Month, day int) time.Time

Date is a utility function to create a date with time set to midnight and the local timezone.

func GetBaseURL

func GetBaseURL(rawURL string) string

GetBaseURL extracts the base URL (scheme and host) from the given raw URL string. If parsing fails, it logs the error and returns an empty string.

func InferYear

func InferYear(month time.Month, windowInMonths int, dt time.Time) int

InferYear infers the most likely year for a given month, based on a reference date and a window in months.

func SundayOfTheWeek

func SundayOfTheWeek(t time.Time) time.Time

SundayOfTheWeek returns the date of the Sunday of the week based on a provided date.

func WeekNo

func WeekNo(t time.Time) int

WeekNo calculates the week number of the year based on a provided date. The weeks are considered to start on Sundays.

Types

type AutoTasker

type AutoTasker interface {
	// CaptureTimes captures time entries based on the provided options.
	CaptureTimes(entries TimeEntries, opts CaptureOptions) error
}

AutoTasker is an interface for capturing time entries.

type CaptureOptions

type CaptureOptions struct {
	Credentials     Credentials // Authentication details.
	DryRun          bool        // If true, does a dry run without actual capture.
	UserDisplayName string      // Display name of the user in AutoTask, this available under the user profile. This value is used to find time entries for the user.
	BrowserType     string      // Type of the browser to use, e.g., "chromium", "firefox" and "webkit".
	Headless        bool        // If true, browser operates in headless mode.
	DateFormat      string      // Format for date representation.
	DayFormat       string      // Format for day representation.
}

CaptureOptions defines the options for the CaptureTimes method.

type Credentials

type Credentials struct {
	Username string
	Password string
}

Credentials holds the authentication details, currently unused in this snippet.

type RequestEntry

type RequestEntry struct {
	Id        int       `json:"id"`
	IsTicket  bool      `json:"isTicket"`
	Date      time.Time `json:"date"`
	StartTime string    `json:"startTime"`
	Duration  float32   `json:"duration"`
	Summary   string    `json:"summary"`
	Project   string    `json:"project"`
}

RequestEntry represents a single entry as received in a JSON request.

func UnmarshalToRequestEntries

func UnmarshalToRequestEntries(data []byte) ([]RequestEntry, error)

UnmarshalToRequestEntries converts JSON data into a slice of RequestEntry.

type TimeEntries

type TimeEntries []*TimeEntry

func UnmarshalToTimeEntries

func UnmarshalToTimeEntries(data []byte, dateFormat string) (TimeEntries, error)

UnmarshalToTimeEntries converts JSON data into a TimeEntries.

func (TimeEntries) ByDate

func (entries TimeEntries) ByDate(date time.Time) TimeEntries

ByDate retrieves all entries that match a given date

func (TimeEntries) ById

func (a TimeEntries) ById(id int) TimeEntries

ById retrieves entries based on their Id

func (TimeEntries) DistinctIds

func (a TimeEntries) DistinctIds() []int

DistinctIds returns a list of distinct Ids from the TimeEntries

func (TimeEntries) DistinctWeekNos

func (a TimeEntries) DistinctWeekNos() []int

DistinctWeekNos returns a slice of distinct week numbers

func (TimeEntries) GroupByWeekNo

func (a TimeEntries) GroupByWeekNo() map[int]TimeEntries

GroupByWeekNo groups the TimeEntries based on their week number

func (TimeEntries) Len

func (t TimeEntries) Len() int

func (TimeEntries) Less

func (t TimeEntries) Less(i, j int) bool

func (TimeEntries) PrintSummary

func (entries TimeEntries) PrintSummary()

PrintSummary prints a summary table of the time entries.

func (TimeEntries) SortByDateAndTime added in v0.0.11

func (t TimeEntries) SortByDateAndTime()

SortByDateAndTime sorts the entries by their Date and StartTimeStr

func (TimeEntries) SplitEntries

func (a TimeEntries) SplitEntries() (TimeEntries, TimeEntries)

SplitEntries splits the TimeEntries into two lists based on their IsTicket flag, the first list contains tickets, the second contains tasks

func (TimeEntries) Swap

func (t TimeEntries) Swap(i, j int)

type TimeEntry

type TimeEntry struct {
	Id           int
	IsTicket     bool // if not a ticket, it's a task
	Date         time.Time
	DateStr      string
	StartTimeStr string
	Duration     float32 // in hours
	Summary      string
	Project      string

	// Derived properties
	Exists             bool
	Submitted          bool
	Error              error
	DurationHours      int
	DurationMinutes    float32
	DurationHoursStr   string
	DurationMinutesStr string
	WeekNo             int
	WeekPeerLocator    interface{}
}

func NewEntry

func NewEntry(id int,
	isTicket bool,
	date time.Time,
	startTimeStr string,
	duration float32,
	summary string,
	project string,
	dateFormat string) *TimeEntry

NewEntry constructs a TimeEntry and calculates its derived properties

func (*TimeEntry) SetError

func (te *TimeEntry) SetError(err error)

SetError sets an error for the TimeEntry

Jump to

Keyboard shortcuts

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