Giter VIP home page Giter VIP logo

extended's People

Contributors

dependabot-preview[bot] avatar richrdkng avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

extended's Issues

docs(tutorial): write a tutorial doc about duration-string

๐Ÿš€ Description

Possibilities of duration-strings and the possible syntax cannot be found in a concise, simple manner.

The term duration-string refers to the main argument of duration (e.g.: '1h 2min 3sec').

๐Ÿ’ก Solution

Write a tutorial doc, either in this repository, or as a separate, tutorial article with a link to this repo about the possibilities and the usage of duration-strings.

๐Ÿ’ฌ Additional Context

This issue can be linked and resolved with #11.

feat(return-unit-shorthand): add return unit as 2nd or 3rd arg shorthand option

If the return unit is provided as 2nd or 3rd argument by specifying the bare unit (e.g.:'sec', 'hours', 'days', etc.), accept it as a return unit shorthand ({ unit: 'ms .. weeks' }).

For example, instead of:

duration('1 day', { unit: 'sec' }) // === 86400 in seconds

accept the return unit as 2nd or 3rd (with fallback) argument:

duration('1 day', 'sec')  // === 86400 in seconds
duration('1 day', '0', 'sec')  // === 86400 in seconds

feat(random-range): duration range with inclusive random result

Add a range feature for 2 given duration, which 2 given duration values will be the random min and max values, inclusive [min, max].

duration('1s-2s') // will return between 1s and 2s randomly (including 1s and 2s too)
duration('55m-1.5h') // will return between 55m and 1.5h (or 90m) randomly

feat(additional-units): add additional units

Add more units with configurable durations (e.g.: how long a year should actually be - 365 days exactly, or 365.25 days, or just use from option to calculate from):

  • months ('month', 'months')
  • quarters ('q', 'qrt', 'quarter', 'quarters')
  • years ('y', 'yr', 'year', 'years')

For example, if 1 year is given, by default, calculate a year from the time of calling the function, e.g.: duration('1 year') is called on 2020-01-30 12:00:00, in this case 1 year won't be ~365.25 days, but calculate the actual milliseconds between 2020-01-30 12:00:00 and 2021-01-30 12:00:00 - (in this case it's 366 days === 31622400000 milliseconds).


Also consider providing a calculate duration from option, e.g.:

// default value
duration('1 year', { from: 'now' })

// custom date (string as human-readable date)
duration('1 year', { from: '2020-01-30 12:00:00' })

// custom date (a number in milliseconds? or seconds? from epoch) - consider ? later
duration('1 year', { from: 1580385600000 }) // 2020-01-30 12:00:00 GMT in epoch milliseconds

Minus sign at the beginning is applied only to the first unit in composite input

๐Ÿž Description

Starting a composite duration with a minus sign will only treat the first block as negative.

Example:
1h30m => 5400000 CORRECT
-1h30m => -1800000 WRONG: This translates to -30 minutes
-1h30m => -5400000 CORRECT but weird

๐Ÿ’ก Expected Behavior

The entire duration is set to negative, so for example, having -1h30m should return -5400000. This is currently achieved with -1h-30m, which is very weird.

โ†ฉ๏ธ Is This a Regression?

No.

๐Ÿ”ฌ Minimal Reproduction

Steps to reproduce the behavior:

  1. Use a composite duration that begins with a minus sign, but with no subsequent minus signs afterwards.

๐Ÿ”ฅ Error or Exception

If there's an error or an exception, please share it below:

None.

๐ŸŒ Environment

Describe your relevant environment (device, OS, browser, Node.js, packages, etc.):

Node v14.15.4
NPM 6.14.10
Windows 10 64bit
@standards/duration: 1.1.3

๐Ÿ–ผ๏ธ Screenshots

roleduration

๐Ÿ’ฌ Anything Else?

None.

feat(about-modifier): about/roughly modifier for the given duration

Add a ~ modifier for the given duration, that signals, that the given duration should be a range with min and max values based on the given duration with 10% difference.

duration('~10s') // equals to duration('9s-11s')
duration('~1m') // equals to duration('0.9m-1.1m') or duration('54s-66s')
duration('~2.5s') // equals to duration('2.25s-2.75s')

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.