date

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package date returns date objects or components of a date object

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DateAdd

func DateAdd[T expression.DateExpression, N expression.NumberExpression](startDate T, unit options.MongoTimeUnit, amount N, options DateOptions) dateOperator

DateAdd NewDefaultStage in version 5.0. Increments a Date object by a specified number of time units. The $dateAdd expression has the following syntax:

{
  $dateAdd: {
     startDate: <Expression>,
     unit: <Expression>,
     amount: <Expression>,
     timezone: <tzExpression>
  }
}

Returns a Date. The startDate can be any expression that resolves to type Date, Timestamp or ObjectId. No matter which data type is used as input, the value returned will be a Date object.

func DateDiff

func DateDiff[T expression.DateExpression, N expression.NumberExpression](startDate, endDate T, unit options.MongoTimeUnit, amount N, options DateDiffOptions) dateOperator

DateDiff NewDefaultStage in version 5.0. Returns the difference between two dates. The $dateDiff expression has this syntax:

{
  $dateDiff: {
     startDate: <Expression>,
     endDate: <Expression>,
     unit: <Expression>,
     timezone: <tzExpression>,
     startOfWeek: <String>
  }
}

Subtracts startDate from endDate. Returns an integer in the specified unit.

func DateFromParts

func DateFromParts(year int32, options DateFromPartsOptions) dateOperator

DateFromParts Constructs and returns a Date object given the date's constituent properties.

The $dateFromParts expression has the following syntax:

{
   $dateFromParts : {
       'year': <year>, 'month': <month>, 'day': <day>,
       'hour': <hour>, 'minute': <minute>, 'second': <second>,
       'millisecond': <ms>, 'timezone': <tzExpression>
   }
}

func DateFromPartsIso

func DateFromPartsIso(isoWeekYear int32, options DateFromPartsOptions) dateOperator

DateFromPartsIso Constructs and returns a Date object given the date's constituent properties. ISO week date format using the following syntax:

{
   $dateFromParts : {
       'isoWeekYear': <year>, 'isoWeek': <week>, 'isoDayOfWeek': <day>,
       'hour': <hour>, 'minute': <minute>, 'second': <second>,
       'millisecond': <ms>, 'timezone': <tzExpression>
   }
}

func DateFromString

func DateFromString(dateString string, options DateFromStringOptions) dateOperator

DateFromString Converts a date/time string to a date object.

The $dateFromString expression has the following syntax:

{ $dateFromString: {
    dateString: <dateStringExpression>,
    format: <formatStringExpression>,
    timezone: <tzExpression>,
    onError: <onErrorExpression>,
    onNull: <onNullExpression>
} }

func DateSubtract

func DateSubtract[T expression.DateExpression, N expression.NumberExpression](startDate T, unit options.MongoTimeUnit, amount N, options DateOptions) dateOperator

DateSubtract NewDefaultStage in version 5.0. Decrements a Date object by a specified number of time units. The $dateSubtract expression has the following syntax:

{
  $dateSubtract: {
     startDate: <Expression>,
     unit: <Expression>,
     amount: <Expression>,
     timezone: <tzExpression>
  }
}

Returns a Date. The startDate can be any expression that resolves to type Date, Timestamp or ObjectId. No matter which data type is used as input, the value returned will be a Date object.

func DateToParts

func DateToParts[T expression.DateExpression](date T, options DateToPartsOptions) dateOperator

DateToParts Returns a document that contains the constituent parts of a given BSON Date value as individual properties. The properties returned are year, month, day, hour, minute, second and millisecond. You can set the iso8601 property to true to return the parts representing an ISO week date instead. This will return a document where the properties are isoWeekYear, isoWeek, isoDayOfWeek, hour, minute, second and millisecond. The $dateToParts expression has the following syntax:

{
   $dateToParts: {
       'date' : <dateExpression>,
       'timezone' : <timezone>,
       'iso8601' : <boolean>
   }
}

func DateToString

func DateToString[T expression.DateExpression](date T, options DateToStringOptions) dateOperator

DateToString Converts a date object to a string according to a user-specified format. The $dateToString expression has the following operator expression syntax:

{ $dateToString: {
   date: <dateExpression>,
   format: <formatString>,
   timezone: <tzExpression>,
   onNull: <expression>
} }

func DateTrunc

func DateTrunc[T expression.DateExpression](date T, unit options.MongoTimeUnit, options DateTruncOptions) dateOperator

DateTrunc NewDefaultStage in version 5.0. Truncates a date. $dateTrunc syntax:

{
  $dateTrunc: {
     date: <Expression>,
     unit: <Expression>,
     binSize: <Expression>,
     timezone: <tzExpression>,
     startOfWeek: <Expression>
  }
}

func DayOfMonth

func DayOfMonth[T expression.DateExpression](date T, options DateOptions) dateOperator

DayOfMonth Returns the day of the month for a date as a number between 1 and 31. The $dayOfMonth expression has the following operator expression syntax: { $dayOfMonth: <dateExpression> } The argument can be: An expression that resolves to a Date, a Timestamp, or an ObjectID. A document with this format: { date: <dateExpression>, timezone: <tzExpression> }

func DayOfWeek

func DayOfWeek[T expression.DateExpression](date T, options DateOptions) dateOperator

DayOfWeek Returns the day of the week for a date as a number between 1 (Sunday) and 7 (Saturday). The $dayOfWeek expression has the following operator expression syntax: { $dayOfWeek: <dateExpression> } The argument can be: An expression that resolves to a Date, a Timestamp, or an ObjectID. A document with this format: { date: <dateExpression>, timezone: <tzExpression> }

func DayOfYear

func DayOfYear[T expression.DateExpression](date T, options DateOptions) dateOperator

DayOfYear Returns the day of the year for a date as a number between 1 and 366. The $dayOfYear expression has the following operator expression syntax: { $dayOfYear: <dateExpression> } The argument can be: An expression that resolves to a Date, a Timestamp, or an ObjectID. A document with this format: { date: <dateExpression>, timezone: <tzExpression> }

func Hour

func Hour[T expression.DateExpression](date T, options DateOptions) dateOperator

Hour Returns the hour portion of a date as a number between 0 and 23. The $hour expression has the following operator expression syntax: { $hour: <dateExpression> } The argument can be: An expression that resolves to a Date, a Timestamp, or an ObjectID. A document with this format: { date: <dateExpression>, timezone: <tzExpression> }

func IsoDayOfWeek

func IsoDayOfWeek[T expression.DateExpression](date T, options DateOptions) dateOperator

IsoDayOfWeek Returns the weekday number in ISO 8601 format, ranging from 1 (for Monday) to 7 (for Sunday). The $isoDayOfWeek expression has the following operator expression syntax: { $isoDayOfWeek: <dateExpression> } The argument can be: An expression that resolves to a Date, a Timestamp, or an ObjectID. A document with this format: { date: <dateExpression>, timezone: <tzExpression> }

func IsoWeek

func IsoWeek[T expression.DateExpression](date T, options DateOptions) dateOperator

IsoWeek Returns the week number in ISO 8601 format, ranging from 1 to 53. Week numbers start at 1 with the week (Monday through Sunday) that contains the year's first Thursday. The $isoWeek expression has the following operator expression syntax: { $isoWeek: <dateExpression> } The argument can be: An expression that resolves to a Date, a Timestamp, or an ObjectID. A document with this format: { date: <dateExpression>, timezone: <tzExpression> }

func IsoWeekYear

func IsoWeekYear[T expression.DateExpression](date T, options DateOptions) dateOperator

IsoWeekYear Returns the year number in ISO 8601 format. The year starts with the Monday of week 1 and ends with the Sunday of the last week. The $isoWeekYear expression has the following operator expression syntax: { $isoWeekYear: <dateExpression> } The argument can be: An expression that resolves to a Date, a Timestamp, or an ObjectID. A document with this format: { date: <dateExpression>, timezone: <tzExpression> }

func Millisecond

func Millisecond[T expression.DateExpression](date T, options DateOptions) dateOperator

Millisecond Returns the millisecond portion of a date as an integer between 0 and 999. The $millisecond expression has the following operator expression syntax: { $millisecond: <dateExpression> } The argument can be: An expression that resolves to a Date, a Timestamp, or an ObjectID. A document with this format: { date: <dateExpression>, timezone: <tzExpression> }

func Minute

func Minute[T expression.DateExpression](date T, options DateOptions) dateOperator

Minute Returns the minute portion of a date as a number between 0 and 59. The $minute expression has the following operator expression syntax: { $minute: <dateExpression> } The argument can be: An expression that resolves to a Date, a Timestamp, or an ObjectID. A document with this format: { date: <dateExpression>, timezone: <tzExpression> }

func Month

func Month[T expression.DateExpression](date T, options DateOptions) dateOperator

Month Returns the second portion of a date as a number between 0 and 59, but can be 60 to account for leap seconds. The $second expression has the following operator expression syntax: { $second: <dateExpression> } The argument can be: An expression that resolves to a Date, a Timestamp, or an ObjectID. A document with this format: { date: <dateExpression>, timezone: <tzExpression> }

func Second

func Second[T expression.DateExpression](date T, options DateOptions) dateOperator

Second Returns the second portion of a date as a number between 0 and 59, but can be 60 to account for leap seconds. The $second expression has the following operator expression syntax: { $second: <dateExpression> } The argument can be: An expression that resolves to a Date, a Timestamp, or an ObjectID. A document with this format: { date: <dateExpression>, timezone: <tzExpression> }

func ToDate

func ToDate[T expression.DateExpression](date T) dateOperator

ToDate Converts a value to a date. If the value cannot be converted to a date, $toDate errors. If the value is null or missing, $toDate returns null. $toDate has the following syntax:

{
  $toDate: <expression>
}

The $toDate takes any valid expression. The $toDate is a shorthand for the following $convert expression: { $convert: { input: <expression>, to: "date" } }

func Week

func Week[T expression.DateExpression](date T, options DateOptions) dateOperator

Week Returns the week of the year for a date as a number between 0 and 53. Weeks begin on Sundays, and week 1 begins with the first Sunday of the year. Days preceding the first Sunday of the year are in week 0. This behavior is the same as the "%U" operator to the strftime standard library function. The $week expression has the following operator expression syntax: { $week: <dateExpression> } The argument can be: An expression that resolves to a Date, a Timestamp, or an ObjectID. A document with this format: { date: <dateExpression>, timezone: <tzExpression> }

func Year

func Year[T expression.DateExpression](date T, options DateOptions) dateOperator

Year Returns the year portion of a date. The $year expression has the following operator expression syntax: { $year: <dateExpression> } The argument can be: An expression that resolves to a Date, a Timestamp, or an ObjectID. A document with this format: { date: <dateExpression>, timezone: <tzExpression> }

Types

type DateDiffOptions

type DateDiffOptions struct {
	// contains filtered or unexported fields
}

type DateFromPartsOptions

type DateFromPartsOptions struct {
	// contains filtered or unexported fields
}

type DateFromStringOptions

type DateFromStringOptions struct {
	// contains filtered or unexported fields
}

type DateOptions

type DateOptions struct {
	// contains filtered or unexported fields
}

type DateToPartsOptions

type DateToPartsOptions struct {
	// contains filtered or unexported fields
}

type DateToStringOptions

type DateToStringOptions struct {
	// contains filtered or unexported fields
}

type DateTruncOptions

type DateTruncOptions struct {
	// contains filtered or unexported fields
}

type SimpleFormatDate

type SimpleFormatDate[T expression.DateExpression] struct {
	// contains filtered or unexported fields
}

func NewSimpleFormatDate

func NewSimpleFormatDate[T expression.DateExpression](name string, date T, options DateOptions) SimpleFormatDate[T]

func (SimpleFormatDate[T]) BsonDocument

func (s SimpleFormatDate[T]) BsonDocument() *bsonx.BsonDocument

func (SimpleFormatDate[T]) Document

func (s SimpleFormatDate[T]) Document() bson.D

type StartOfWeek

type StartOfWeek string
const (
	Monday    StartOfWeek = "monday"
	Tuesday   StartOfWeek = "tuesday"
	Wednesday StartOfWeek = "wednesday"
	Thursday  StartOfWeek = "thursday"
	Friday    StartOfWeek = "friday"
	Saturday  StartOfWeek = "saturday"
	Sunday    StartOfWeek = "sunday"
)

func (StartOfWeek) String

func (w StartOfWeek) String() string

Jump to

Keyboard shortcuts

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