Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/siverpinevalley/parseduration

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/siverpinevalley/parseduration

  • v0.0.0-20240823050328-d9b7165d7d3a
  • Source
  • Go
  • Socket score

Version published
Created
Source

Golang parseduration

Go Report Card

The built-in package time offer very useful functions.

However, when you use time.ParseDuration, you cannot use time unit that is bigger than hours. This package also offer day, week, month, year time units for parsing string to duration.

Installation

go get https://github.com/SiverPineValley/parseduration

Format

The standard for parsing is same as time.ParseDuration. You can use ParseDuration sending parameters such as 2w3d20h.

Negative numbers are also provided, and if you enter only letters without entering a number, it will be recognized as 0. d == 0d

Standard

Time units are as provided in the table below. A time unit that is not provided or a time unit that is duplicated will cause an error.

In addition, the maximum value for each unit was not separately filtered.

Time UnitDuration
ns1 Nano seconds
us1 Micro Seconds
ms1 Milli Seconds
s1 Seconds
m1 Minutes
h1 Hours
d1 Days
w1 Weeks (7 Days)
M1 Months (30 Days)
y1 Years (365 Days)

Examples

package main

import (
	"fmt"
    pd "github.com/SiverPineValley/parseduration"
)

// It returns 4 weeks + 2 days + 3 hours Duration
func main() {
	fmt.Println(pd.ParseDuration("4w2d3h"))
}

FAQs

Package last updated on 23 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc