types

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package types provides shared types used across the Basecamp SDK.

Package types provides shared types used across the Basecamp SDK.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Date

type Date struct {
	Year  int        // Year (e.g., 2024)
	Month time.Month // Month of the year (January = 1, ...)
	Day   int        // Day of the month, starting at 1
}

Date represents a calendar date (year, month, day) without time or timezone. Use this for date-only fields like due_on and starts_on.

func DateOf

func DateOf(t time.Time) Date

DateOf returns the Date portion of a time.Time in that time's location.

func ParseDate

func ParseDate(s string) (Date, error)

ParseDate parses a string in YYYY-MM-DD format.

func Today

func Today() Date

Today returns today's date in the local timezone.

func (Date) AddDays

func (d Date) AddDays(n int) Date

AddDays returns the date n days from d.

func (Date) AddMonths

func (d Date) AddMonths(n int) Date

AddMonths returns the date n months from d.

func (Date) AddYears

func (d Date) AddYears(n int) Date

AddYears returns the date n years from d.

func (Date) After

func (d Date) After(other Date) bool

After reports whether d is after other.

func (Date) Before

func (d Date) Before(other Date) bool

Before reports whether d is before other.

func (Date) Compare

func (d Date) Compare(other Date) int

Compare compares d and other. Returns -1 if d < other, 0 if equal, +1 if d > other.

func (Date) DaysSince

func (d Date) DaysSince(s Date) int

DaysSince returns the number of days from s to d (d - s).

func (Date) Equal

func (d Date) Equal(other Date) bool

Equal reports whether d and other represent the same date.

func (Date) GoString

func (d Date) GoString() string

GoString returns a Go-syntax representation for debugging.

func (Date) In

func (d Date) In(loc *time.Location) time.Time

In returns the time.Time corresponding to midnight of the date in the given location.

func (Date) IsValid

func (d Date) IsValid() bool

IsValid reports whether the date represents a valid calendar date.

func (Date) IsZero

func (d Date) IsZero() bool

IsZero reports whether the date is the zero value.

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. Zero dates marshal as null, valid dates as "YYYY-MM-DD".

func (Date) MarshalText

func (d Date) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Date) String

func (d Date) String() string

String returns the date in YYYY-MM-DD format.

func (Date) UTC

func (d Date) UTC() time.Time

UTC returns the time.Time corresponding to midnight UTC of the date.

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. Accepts "YYYY-MM-DD" strings and null.

func (*Date) UnmarshalText

func (d *Date) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Date) Weekday

func (d Date) Weekday() time.Weekday

Weekday returns the day of the week.

type FlexInt added in v0.4.0

type FlexInt int32

FlexInt is an int32 that unmarshals from any JSON number whose value is integral and fits in 32 bits. The BC3 API serializes pixel dimensions as floats (e.g. 1024.0); Go's encoding/json rejects those into plain int fields. FlexInt bridges this wire-format mismatch without lying in the spec.

Non-integral values (1024.5) and out-of-range values (1e20) are rejected to match the int32 schema in openapi.json.

func (FlexInt) MarshalJSON added in v0.4.0

func (fi FlexInt) MarshalJSON() ([]byte, error)

MarshalJSON writes the value as an integer.

func (*FlexInt) UnmarshalJSON added in v0.4.0

func (fi *FlexInt) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts any JSON number whose value is an integer within int32 range.

type FlexibleInt64 added in v0.7.1

type FlexibleInt64 int64

FlexibleInt64 is an int64 that unmarshals from either a JSON number or a JSON string containing an integer. The BC3 API sometimes serializes person IDs as strings (e.g. "12345") in notification responses while returning plain integers elsewhere. FlexibleInt64 bridges this wire-format mismatch without lying in the spec.

Non-integral JSON numbers (1024.5) and values outside int64 range are rejected. Non-numeric strings (e.g. "basecamp" for system-generated entities) unmarshal to zero — the spec declares the field as integer, so a non-numeric value means the entity has no meaningful numeric ID. The number path uses json.Number to avoid float64 precision loss for values beyond 2^53.

func (FlexibleInt64) MarshalJSON added in v0.7.1

func (fi FlexibleInt64) MarshalJSON() ([]byte, error)

MarshalJSON writes the value as a JSON integer.

func (*FlexibleInt64) UnmarshalJSON added in v0.7.1

func (fi *FlexibleInt64) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts a JSON number or a JSON string whose value is an integer within int64 range.

type FlexibleTime added in v0.4.0

type FlexibleTime struct {
	time.Time
	// contains filtered or unexported fields
}

FlexibleTime is a time.Time that can unmarshal from RFC3339, RFC3339Nano, or date-only ("2006-01-02") strings. Date-only values are treated as midnight UTC. This supports API responses where all-day schedule entries return dates without times.

It remembers which form it parsed and marshals that form back: a bare date re-emits as a bare date, a timestamp as a timestamp. BC3 re-parses a timestamp in the account's own time zone, so an all-day bound rendered as "2026-08-04T00:00:00Z" lands on the previous day anywhere west of UTC — a read-modify-write that widened the date on input and narrowed it on output moved the entry (#633).

func (FlexibleTime) AppendText added in v0.19.0

func (ft FlexibleTime) AppendText(b []byte) ([]byte, error)

AppendText implements encoding.TextAppender with the same form MarshalText emits; the promoted time.Time.AppendText would append the RFC3339 form of a bare date.

func (FlexibleTime) DateOnly added in v0.19.0

func (ft FlexibleTime) DateOnly() bool

DateOnly reports whether the value was parsed from a bare date, in which case it marshals back as one.

func (FlexibleTime) MarshalJSON added in v0.4.0

func (ft FlexibleTime) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for FlexibleTime. A value parsed from a bare date marshals as that date, even "0001-01-01", which is Go's zero time and would otherwise collapse to null; a zero time that was never parsed from a date marshals as null; any other time uses time.Time's JSON encoding.

func (FlexibleTime) MarshalText added in v0.19.0

func (ft FlexibleTime) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler: the bare date when one was parsed, otherwise time.Time's RFC3339 text.

func (*FlexibleTime) UnmarshalJSON added in v0.4.0

func (ft *FlexibleTime) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for FlexibleTime.

func (*FlexibleTime) UnmarshalText added in v0.19.0

func (ft *FlexibleTime) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler. Defined here rather than promoted from the embedded time.Time so that every decode path, not only JSON, records which form it parsed — a promoted UnmarshalText would replace the time and leave a stale bare-date flag behind.

Jump to

Keyboard shortcuts

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