datehelpers

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package datehelpers provides functions for parsing CQL date, datetime and time strings.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedPrecision = errors.New("unsupported precision")

ErrUnsupportedPrecision is returned when a precision is not supported.

Functions

func DateString

func DateString(d time.Time, precision model.DateTimePrecision) (string, error)

DateString returns a CQL Date string representation of a Date.

func DateTimeString

func DateTimeString(d time.Time, precision model.DateTimePrecision) (string, error)

DateTimeString returns a CQL DateTime string representation of a DateTime.

func ParseDate

func ParseDate(rawStr string, evaluationLoc *time.Location) (time.Time, model.DateTimePrecision, error)

ParseDate parses a CQL Date string into a golang time. CQL Dates start with @ and follow a subset of ISO-8601.

CQL Dates do not have timezone offsets, but when converting a Date to a DateTime the offset of the evaluation timestamp is used. Since all golang times require a location we set all Date offset to the offset of the evaluation timestamp.

func ParseDateTime

func ParseDateTime(rawStr string, evaluationLoc *time.Location) (time.Time, model.DateTimePrecision, error)

ParseDateTime parses a CQL DateTime string into a golang time. CQL Dates start with @ and follow a subset of ISO-8601. If rawStr does not include an offset then evaluationLoc will be used. Otherwise, the offset in rawStr is used.

func ParseFHIRDate

func ParseFHIRDate(d *d4pb.Date, evaluationLoc *time.Location) (time.Time, model.DateTimePrecision, error)

ParseFHIRDate parses a FHIR Date proto into a golang time. Similar to other helpers in this package, if the proto does not have a timezone set then evaluationLoc will be used.

To match ParseDate, we take the year, month, and day values from the FHIR proto (in the FHIR proto's timezone) and create a new time.Time at 0:00:00 in the evaluationLoc timezone, which is the default timezone we attach to all CQL Dates in our codebase.

func ParseFHIRDateTime

func ParseFHIRDateTime(d *d4pb.DateTime, evaluationLoc *time.Location) (time.Time, model.DateTimePrecision, error)

ParseFHIRDateTime parses a FHIR DateTime proto into a golang time. Similar to other helpers in this package, if the proto does not have a timezone set then evaluationLoc will be used.

func ParseTime

func ParseTime(rawStr string, evaluationLoc *time.Location) (time.Time, model.DateTimePrecision, error)

ParseTime parses a CQL Time string into a golang time. CQL Time start with @ and roughly follow ISO-8601.

func TimeString

func TimeString(d time.Time, precision model.DateTimePrecision) (string, error)

TimeString returns a CQL Time string representation of a Time.

Types

This section is empty.

Jump to

Keyboard shortcuts

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