extended-library / extended Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
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'
).
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.
This issue can be linked and resolved with #11.
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
Negative durations are handled currently like in the 2. option!
Add an option to handle negative durations:
duration(-1) === 0
duration(-1) === -1
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):
'month'
, 'months'
)'q'
, 'qrt'
, 'quarter'
, 'quarters'
)'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
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')
readme badges and links
readme decor: https://www.npmjs.com/package/year-range
own social sites, project's twitter page
readme - Usage section - basic examples, refactor index.js
too
author section
readme icons
.github dir and docs
finish logo and media with docs and license
readme structure
duration-string
can be extracted as a separate, open standard package and repository for better testing and documentation.
Extract duration-string
as @standards/duration-string
on NPM and also on GitHub.
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
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.
No.
Steps to reproduce the behavior:
If there's an error or an exception, please share it below:
None.
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
None.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.