timereplace

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 1 Imported by: 0

README

koron-go/timereplace

PkgGoDev Actions/Go Go Report Card Ask DeepWiki

timereplace provides the Replace() function equivalent to Python's date.replace.

Documentation

Overview

Package timereplace provides the Replace() function equivalent to Python's date.replace.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Replace

func Replace(orig time.Time, v Values) time.Time

Replace returns a new time.Time with some of the values in the given time.Time argument overwritten. The value to be rewritten is an element of the argument Values that is not nil.

Example
package main

import (
	"fmt"
	"time"

	"github.com/koron-go/timereplace"
)

func main() {
	origtime := time.Date(2006, 1, 2, 3, 4, 5, 999999999, time.UTC)
	fmt.Println(origtime.Format(time.RFC3339Nano))

	modtime := timereplace.Replace(origtime, timereplace.Values{
		Year:  new(2026),
		Month: new(time.Month(2)),
		Day:   new(19),
	})
	fmt.Println(modtime.Format(time.RFC3339Nano))

}
Output:

2006-01-02T03:04:05.999999999Z
2026-02-19T03:04:05.999999999Z

Types

type Values

type Values struct {
	Year  *int
	Month *time.Month
	Day   *int
	Hour  *int
	Min   *int
	Sec   *int
	Nsec  *int
	Loc   *time.Location
}

Values specifies the time.Time fields and its values to be rewritten with Replace.

Jump to

Keyboard shortcuts

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