tinytime

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: MIT Imports: 2 Imported by: 0

README

tinytime

TinyGo-compatible time package for Go, using syscall/js on WASM to keep binaries small and leverage native JS time APIs.

Minimal and portable time utility package for Go and TinyGo with WebAssembly support. When compiled for wasm (GOOS=js GOARCH=wasm), it uses syscall/js to access native JavaScript time APIs (Date.now, performance.now, etc.), drastically reducing binary size by avoiding the Go standard library. For non-WASM targets, it falls back to the standard time package. Ideal for frontend projects where binary size and compatibility with JavaScript environments matter.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TimeProvider

type TimeProvider interface {
	// UnixNano retrieves the current Unix timestamp in nanoseconds.
	// It creates a new JavaScript Date object, gets the timestamp in milliseconds,
	// converts it to nanoseconds, and returns the result as an int64.
	// eg: 1624397134562544800
	UnixNano() int64
	//	ts := int64(1609459200) // January 1, 2021 00:00:00 UTC
	//	formattedDate := UnixSecondsToDate(ts)
	//	println(formattedDate) // Output: "2021-01-01 00:00:00"
	UnixSecondsToDate(int64) string
	// UnixNanoToTime converts a Unix timestamp in nanoseconds to a formatted time string.
	// Format: "15:04:05" (hour:minute:second)
	// It accepts a parameter of type any and attempts to convert it to an int64 Unix timestamp in nanoseconds.
	// eg: 1624397134562544800 -> "15:32:14"
	// supported types: int64, int, float64, string
	UnixNanoToTime(any) string
}

TimeProvider define la interfaz para utilidades de tiempo implementada tanto para Go estándar como para WASM/JS.

func NewTimeProvider

func NewTimeProvider() TimeProvider

NewTimeProvider retorna la implementación correcta según el entorno de compilación.

Jump to

Keyboard shortcuts

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