GithubHelp home page GithubHelp logo

duration-fns's People

Contributors

alexander-mart avatar altbdoor avatar dlevs avatar haydn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

duration-fns's Issues

Add format()

Usage:

import { parse , format } from 'duration-fns'

const duration = parse('PT1M30S')
console.log(format(duration, 'mm:ss'))  // 01:30

Negative duration format

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.

Here is a link to another bug report that is related that includes documentation from ISO specification

Parse by pettern string

Usage:

import { parse } from 'duration-fns'

const duration = parse('01:30', 'mm:ss')
console.log(duration)  // { minutes: 1, seconds: 30 }

Error "Failed to parse source map from ..." when using Create React App v5

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

Add date reference for conversions

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

Why use comma as decimal separator

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: '.',
})

Durations can be incorrect in certain timezones

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?

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.