bublyk

package module
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

README

Tests GitHub release MIT license codecov lint workflow help wanted

bublyk

The package introduces the Date type, specifically designed for instances where only the date in UTC location is required, without the need for time details. In comparison to the time.Time type, Date offers several advantages:

  • It consumes significantly less memory.
  • It eliminates the need for boilerplate code when working with dates.
  • It allows for straightforward comparisons using operators such as >, <, and others.

Additionally, it natively supports the pgx package. This means you can directly scan into the Date type and use Date as an argument in queries.

Usage

package main

import (
    "context"
    "fmt"
    "github.com/kaatinga/bublyk"
    "github.com/jackc/pgx/v4/pgxpool"
)

func main() {
    ctx := context.Background()
    pool, err := pgxpool.Connect(ctx, "postgres://postgres:postgres@localhost:5432/postgres")
    if err != nil {
        panic(err)
    }
    defer pool.Close()

    _, err = pool.Exec(ctx, "CREATE TABLE IF NOT EXISTS test (test_date DATE)")
    if err != nil {
        panic(err)
    }

    inputDate := bublyk.Now()
    var returnedDate bublyk.Date
    err = pool.QueryRow(ctx, "INSERT INTO test(test_date) VALUES($1) RETURNING test_date", inputDate).Scan(&returnedDate)
    if err != nil {
        panic(err)
    }

    fmt.Println(inputDate, returnedDate)
}

Will be happy to everyone who want to participate in the work on the bublyk package.

Documentation

Index

Constants

View Source
const ErrUnrecognizedFormat consterrs.Error = "unknown date format"
View Source
const (
	PostgreSQLFormat = "2006-01-02"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Date

type Date uint16

Date represents a calendar date starting 2000 year and finishing the year 2127.

func CurrentMonth

func CurrentMonth() Date

func NewDate

func NewDate(year uint16, month, day byte) Date

func NewDateFromTime

func NewDateFromTime(t *time.Time) Date

NewDateFromTime create new date using time.Time model.

func Now

func Now() Date

func Parse

func Parse(formattedDate string) (Date, error)

func (Date) DMYWithDots

func (thisDate Date) DMYWithDots() string

DMYWithDots returns date as string in the DD.MM.YYYY format.

func (Date) Day

func (thisDate Date) Day() byte

func (*Date) DecodeBinary added in v1.0.4

func (thisDate *Date) DecodeBinary(_ *pgtype.ConnInfo, src []byte) error

func (*Date) DecodeText added in v1.0.4

func (thisDate *Date) DecodeText(_ *pgtype.ConnInfo, src []byte) error

func (Date) EncodeBinary added in v1.0.4

func (thisDate Date) EncodeBinary(_ *pgtype.ConnInfo, buf []byte) ([]byte, error)

func (Date) EncodeText added in v1.0.4

func (thisDate Date) EncodeText(_ *pgtype.ConnInfo, buf []byte) ([]byte, error)

func (Date) Format

func (thisDate Date) Format(layout string) string

func (Date) IsFuture

func (thisDate Date) IsFuture() bool

func (Date) IsSet

func (thisDate Date) IsSet() bool

func (Date) Month

func (thisDate Date) Month() byte

func (Date) MonthAfter

func (thisDate Date) MonthAfter(date Date) bool

MonthAfter checks whether the date at least one month after the target date or not.

func (Date) MonthBefore

func (thisDate Date) MonthBefore(date Date) bool

MonthBefore checks whether the date at least one month before the target date or not.

func (Date) NextDay

func (thisDate Date) NextDay() Date

func (Date) NextMonth

func (thisDate Date) NextMonth() Date

NextMonth returns date which month number in incremented by one. The month number may change greater if the source day does not exist in the next month.

func (Date) NextWeek

func (thisDate Date) NextWeek() Date

func (Date) PreviousDay

func (thisDate Date) PreviousDay() Date

func (Date) PreviousMonth

func (thisDate Date) PreviousMonth() Date

PreviousMonth returns date which month number in decremented by one. The month number may change greater if the source day does not exist in the previous month.

func (Date) PreviousWeek

func (thisDate Date) PreviousWeek() Date

func (Date) String

func (thisDate Date) String() string

String returns date as string in the default PostgreSQL date format, YYYY-MM-DD.

func (Date) Time

func (thisDate Date) Time() *time.Time

func (Date) Value added in v1.0.4

func (thisDate Date) Value() (driver.Value, error)

Value implements the database/sql/driver Valuer interface.

func (Date) Year

func (thisDate Date) Year() uint16

Jump to

Keyboard shortcuts

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