dlevs / duration-fns Goto Github PK
View Code? Open in Web Editor NEWFunctions for working with durations.
License: MIT License
Functions for working with durations.
License: MIT License
Usage:
import { parse , format } from 'duration-fns'
const duration = parse('PT1M30S')
console.log(format(duration, 'mm:ss')) // 01:30
Currently, when we have a negative duration and call duration.toString
, it returns a string that is not compatible with certain frameworks like .NET.
For example:
const offset = duration.negate({ minutes: 300 })
duration.toString(offset)); // result: PT-300M
.NET expects -PT300M
.
I am wondering if it is possible to have an option to configure the output of duration.toString
.
This is a great library, but I'd love to have typescript maps and make them available through @types/duration-fns
Usage:
import { parse } from 'duration-fns'
const duration = parse('01:30', 'mm:ss')
console.log(duration) // { minutes: 1, seconds: 30 }
When importing this library in an app using Create React App v5, npm start
throws up a bunch of the following errors
WARNING in ./node_modules/duration-fns/dist/abs.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '/Users/camillef/Code/app/node_modules/duration-fns/src/abs.ts' file: Error: ENOENT: no such file or directory, open '/Users/camillef/Code/app/node_modules/duration-fns/src/abs.ts'
According to facebook/create-react-app#11767 this is because duration-fns is not correctly including sourcemaps in its npm package
Hi there, great job with this library! Just one problem I'm having involves converting to single units. Would it be possible to add a date reference for conversions like you have done with normalisation?
For example, I would like the following to return a number of full days:
durationFns.toDays({ years: 1, months: 1 })
// 395.4166666666667
durationFns.toDays({ years: 1, months: 1 }, '2018-01-01')
// 396
Commas are mentioned in the spec as the preferred decimal delimiter
As described in your code, commas are used as decimal separators, but in my scenario, commas are not accepted as separators, can this separator be controlled by adding parameters?
like:
.toString(duration, {
decimalDelimiter: ',' // decimalDelimiter: '.',
})
d.between(new Date("2024-02-27"), new Date("2024-03-02"))
{
years: 0,
months: 1,
weeks: 0,
days: -25,
hours: 0,
minutes: 0,
seconds: 0,
milliseconds: 0
}
I'm currently in a GMT-5 timezone which makes the between calculation incorrect.
durationFns.between('2020-02-01', '2020-03-01')
\\ returns { days: -2, months: 1 }
Using the UTC getters should fix this. Can do a PR tomorrow to fix.
Related, would you consider ever having between('2020-01-31', '2020-02-29')
return { days: 29 }
? Or does that overcomplicate the between
algorithm for you?
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.