Git Product home page Git Product logo

synchro's Introduction

🕰️ 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.

synchro's People

Contributors

cia-rana avatar code-hex avatar hsfzxjy avatar nobishino avatar shogo82148 avatar tchssk avatar uji avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

synchro's Issues

Proposal: `(Period[T]) Periodic` and similar methods returns `iter.Seq[Time[T]]` instead of channel

golang/go#61897 がacceptedになりました。

これに伴い、コレクションを返すAPIではiter.Seqを返すことがおそらく一般的になっていくと思います。
例えばGo標準ライブラリのproposal golang/go#53987 (comment) は、最終的にiter.Seqを返すAPIとしてacceptされました。

同様に、synchroでコレクションを返すAPIをiter.Seqに対応させるプランはあるでしょうか?(もしあれば、実装することに興味があります)

具体的には以下のようなものです。
細かいところが十分考えられていないのですが、少し見ていただいた印象としてもしポジティブであればより具体的に考えたいと思っています。

Proposal

synchroではコレクションを返すメソッドとしてPeriod[T]などがunexportedな型periodical[T]を返しており、これの実体は<-chan Time[T]になっていると思います。これの代わりに、iter.Seqを返すようにするというProposalです。

func (Period[T]) Periodic() iter.Seq[Time[T]]

Edit: 最初aliasを使う形で書いていたのですが、言語仕様上できないことに気づき、修正しました。

メリット

  • golang/go#61898 のようなiter.Seqを前提としたAPIと組み合わせられるようになること
  • 将来的に標準的になりそうなAPIに合わせられること

実は具体的なユースケースが手元にあるわけではなく、これを提供することで大きいメリットがあるかどうかはわかっていません。

互換性などについてのノート

nobishino@1fd8814 でテストを書きましたが、少なくとも一部で後方互換性がありません。

  • もともとはperiodical型がchannelなので、channel型の変数に代入できるという性質(テストのProperty 1)があった。periodicalの型定義をiter.Seqに置き換えると、この代入はできなくなる。
  • もともとperiodical型がchannelなので、for ~ range文で直接使うこともできた(テストのProperty 2)。この性質はrange over funcが実装された後のGoバージョンでは維持される。
  • Sliceメソッドを削除する必要が生じる。
    • Sliceメソッドを定義できるようにtype periodical[T TimeZone] iter.Seq[Time[T]]を戻り値とした場合、戻り値の値をiter.Seq[Time[T]]型の変数(関数の引数も含む)にそのままでは代入できなくなる。(型変換をすればできると思われる)

Consider reordering the type params of ConvertTz

Currently ConvertTz has the following signature:

func ConvertTz[T TimeZone, U TimeZone](from Time[T]) Time[U]

Users have to specify both T and U at every call site like ConvertTz[T, U](...). However, if we change it to

func ConvertTz[U TimeZone, T TimeZone](from Time[T]) Time[U] // note that U and T are swapped

Users can simply call with ConvertTz[U](...) and let T be inferred from input arguments, which improves the ergnomics.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.