Categorygithub.com/Code-Hex/synchro
modulepackage
0.5.2
Repository: https://github.com/code-hex/synchro.git
Documentation: pkg.go.dev

# README

🕰️ Synchro: Timezone-typesafe date and time framework for Go

test codecov Go Reference

This is inspired by Rust chrono

Features

  • Timezone-typesafe date and time handling
  • Easy conversion between time zones
  • Support for common date and time operations
  • Compatible with the standard time package
  • Full compatible with ISO8601 (GoDoc)
    • ✅ Dates
      • Years
      • Calendar dates
      • Week dates
      • Quarter dates
      • Ordinal dates
    • ✅ Times
    • ✅ Combined date and time representations
    • ✅ Durations
    • ✅ Time intervals
      • Repeating intervals
    • Note: This package can be used as civil time.
      • Civil time is a time-zone-independent representation of time that follows the rules of the proleptic Gregorian calendar with exactly 24-hour days, 60-minute hours, and 60-second minutes.

Installation

To install Synchro, use go get:

go get github.com/Code-Hex/synchro

Synopsis

To use Synchro, import it in your Go code:

package main

import (
    "fmt"

    "github.com/Code-Hex/synchro"
    "github.com/Code-Hex/synchro/tz"
)

func main() {
    // The current UTC time is fixed to `2023-09-02 14:00:00`.
    utcNow := synchro.Now[tz.UTC]()
    fmt.Println(utcNow)

    jstNow := synchro.Now[tz.AsiaTokyo]()
    fmt.Println(jstNow)
    // Output:
    // 2009-11-10 23:00:00 +0000 UTC
    // 2009-11-11 08:00:00 +0900 JST
}

https://go.dev/play/p/Ql3CM7NLfj0

Please refer to the numerous usage examples on GoDoc for reference.

Utilities

We also have a wide range of very useful utilities!!

If you have a feature request, please open an issue. It would be great if you could provide relevant examples or links that could be helpful.

TODO

  • Support database/sql
  • Support i18n
  • Optimization

Contributing

Contributions to Synchro are welcome!

To contribute, please fork the repository and submit a pull request.

License

Synchro is licensed under the MIT License. See LICENSE for more information.

# Packages

No description provided by the author
No description provided by the author
Package tz provides timezone related types.

# Functions

After waits for the duration to elapse and then sends the current time on the returned channel.
ConvertTz can be used to convert a time from one time zone to another.
In returns timezone-aware time.
New returns the Time corresponding to yyyy-mm-dd hh:mm:ss + nsec nanoseconds in the appropriate zone for that time in the given timezone.
NewPeriod creates a new Period struct between the 'from' and 'to' values you specified.
Now returns the current time with timezone.
NowContext returns the current time stored in the provided context.
NowWithContext returns a new context with the provided time with timezone stored in it.
Parse parses a formatted string and returns the time value it represents.
ParseISO parses an ISO8601-compliant date or datetime string and returns its representation as a Time.
Strptime parses time string with the default location.
Unix returns the local Time corresponding to the given Unix time, sec seconds and nsec nanoseconds since January 1, 1970 UTC.
UnixMicro returns the local Time corresponding to the given Unix time, usec microseconds since January 1, 1970 UTC.
UnixMilli returns the local Time corresponding to the given Unix time, msec milliseconds since January 1, 1970 UTC.

# Structs

NullTime represents a Time[T] that may be null.
Period allows iteration over a set of dates and times, recurring at regular intervals, over a given period.
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

TimeZone represents the timezone.
Unit is a component of the time being built.

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author