Giter VIP home page Giter VIP logo

tstr.jl's Introduction

TStr.jl

This is a Julia package implementing a shorthand method for creating time constants. A convenience package to supplement the Dates standard library.

Installation

import Pkg
Pkg.add(url="https://github.com/GHTaarn/TStr.jl")

Use

using TStr

t"2024-03-29T15:31" # is equivalent to Dates.DateTime("2024-03-29T15:31")
t"2024-03-29"d # is equivalent to Dates.Date("2024-03-29")
t"20:21:22"t # is equivalent to Dates.Time("20:21:22")

More documentation can be obtained using @doc @t_str

Advanced use

Other default suffixes

The u suffix denotes Unix time. There is also a package extension for the TimeZones package that maps the z suffix to ZonedDateTime, e.g.

using TStr

@assert t"1970-01-01T00:01" == 60

using TimeZones

@assert t"2020-11-11T11:11:11.111Z"z == ZonedDateTime("2020-11-11T11:11:11.111Z")

Creating custom suffixes

By default, only standard time format strings can be used, but it is possible to use custom time formats if a custom suffix is defined by using the TStr.set_t_str_suffix function, e.g.

using Dates, TStr

myfunc(s) = Date(s, dateformat"Y u d")
mysuffix = "myformat"
TStr.set_t_str_suffix(mysuffix, myfunc)

@assert t"2024 Feb 29"myformat == Date(2024,2,29)

More documentation can be obtained using @doc TStr.set_t_str_suffix

Feedback

Please report bugs and other issues at https://github.com/GHTaarn/TStr.jl/issues or submit a pull request.

tstr.jl's People

Contributors

ghtaarn avatar

Watchers

 avatar

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.