mdat

package
v0.0.0-...-91c5940 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2017 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SECONDS_PER_DAY  = 24 * 3600     // 86400
	SECONDS_PER_WEEK = 24 * 3600 * 7 // 604800

	YEAR_LOWEST       = 1
	YEAR_MAX_SENTINEL = 10000

	UNIX_SEC_LOWEST         = -62135596800 // -719162 days * 24 * 3600
	UNIX_SEC_1900_01_01     = -2208988800  // -25567 days * 24 * 3600
	UNIX_SEC_1970_01_01     = 0
	UNIX_SEC_UPPER_SENTINEL = 253402300800 // 2932897 days * 24 * 3600

	NUMBER_OF_DAYS_FROM_1900_01_01_TO_LOWEST         = -693595 // dateadd(dy, -693595, '19000101') =  '0001-01-01'
	NUMBER_OF_DAYS_FROM_1900_01_01_TO_UPPER_SENTINEL = 2958464 // dateadd(dy, 2958464, '19000101') = '10000-01-01'
	NUMBER_OF_DAYS_FROM_LOWEST_TO_UPPER_SENTINEL     = NUMBER_OF_DAYS_FROM_1900_01_01_TO_UPPER_SENTINEL - NUMBER_OF_DAYS_FROM_1900_01_01_TO_LOWEST
)
View Source
const (
	PARSE_MODE_DATE     int = 1 // in this mode, time part is ignored and forced to 00:00:00.0
	PARSE_MODE_TIME     int = 2 // in this mode, date part is ignored and forced to 1900-01-01
	PARSE_MODE_DATETIME int = 3
)

Variables

View Source
var (
	TIME_LOWEST              time.Time // 0001.01.01
	TIME_1900_01_01          time.Time
	TIME_1900_01_02_SENTINEL time.Time // used by Sysfunc_dateadd_hour_TIME() etc
	TIME_1970_01_01          time.Time
	TIME_UPPER_SENTINEL      time.Time // 10000.01.01
)
View Source
var (
	Error_style_not_supported = errors.New("style not supported")
	Error_wrong_parts_order   = errors.New("wrong date parts order")
	Error_parse_failed        = errors.New("mydatetime.parse(): datetime parsing error")
)

Functions

func Add_month_duration

func Add_month_duration(year int, month time.Month, day int, month_duration int64) (result_year int, result_month time.Month, result_day int, rsql_err *rsql.Error)

func Add_nanosecond_duration

func Add_nanosecond_duration(mydatetime MyDatetime, nanosecond_duration int64) (result time.Time, rsql_err *rsql.Error)

func Add_second_duration

func Add_second_duration(mydatetime MyDatetime, second_duration int64) (result time.Time, rsql_err *rsql.Error)

func DMY_from_style

func DMY_from_style(style int64) (string, error)

DMY_from_style is used for parsing date, to convert a style number into a year month day order.

func Diff_sec_nsec_absolute

func Diff_sec_nsec_absolute(a time.Time, b time.Time) (delta_sec int64, delta_nsec int64, sign int)

Diff_sec_nsec_absolute returns the difference in seconds and nanoseconds between two dates. delta_sec and delta_nsec are always positive or zero. If b >= a, sign is 1. Else, sign is -1.

func Equal

func Equal(a MyDatetime, b MyDatetime) bool

func Get_time_UTC

func Get_time_UTC() (result time.Time, rsql_err *rsql.Error)

func Last_day_of_month

func Last_day_of_month(year int, month time.Month) int

func Nanoseconds_from_fractions

func Nanoseconds_from_fractions(fractions int64, precision int64) (nanoseconds int64)

Nanoseconds_from_fractions computes nanoseconds from fractions and precision values.

The following conditions must apply. Else -1 is returned, indicating an error.
  - fractions must be 0...999999999
  - precision must be 0...9
  - if precision == 0, fractions must be 0
  - nanoseconds must be 0...999999999

func Parse

func Parse(s []byte, DMY string, style int64, mode int) (res time.Time, err error)

Parse converts a string into a time.Time.

DMY   : 3-letter string describing order of date parts. E.g. "MDY".
style : if 0, order of date parts is given by DMY argument. Else, style will override DMY argument. See DMY_from_style().
mode  : PARSE_MODE_DATE, PARSE_MODE_TIME, PARSE_MODE_DATETIME

Parse returns an 'error' type and not a *rsql.Error, because the caller will create a customized *rsql.Error.

func UTC_to_local

func UTC_to_local(a time.Time) (result time.Time, rsql_err *rsql.Error)

a is an absolute time of an event, with location UTC. We want to create a time, also with location UTC, but containing the year, month, day, hour, minutes, seconds, ns as seen locally.

Types

type MyDatetime

type MyDatetime struct {
	time.Time
}

MyDatetime represents the value stored in DATE, TIME, and DATETIME datatypes.

Note: it has not been declared as "type MyDatetime time.Time" because we want to use the time.Time methods Equal(), After(), etc directly on MyDatetime.
      This way, we avoid type conversion syntax in our code, like time.Time(a) where a is of type MyDatetime.

func (MyDatetime) Has_no_time_part

func (mydatetime MyDatetime) Has_no_time_part() bool

Has_no_time_part checks if time part is 00:00:00.0.

func (MyDatetime) String

func (a MyDatetime) String() string

Jump to

Keyboard shortcuts

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