Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement: @kitsuyui/luxon-ext #225

Merged
merged 1 commit into from
Mar 30, 2024
Merged

Implement: @kitsuyui/luxon-ext #225

merged 1 commit into from
Mar 30, 2024

Conversation

kitsuyui
Copy link
Owner

@kitsuyui kitsuyui commented Mar 30, 2024

This package provides some extensions for Luxon.

import { Duration } from 'luxon'
import { toHumanDurationExtended, toHumanDurationWithTemporal, toHumanDurationWithDiff } from '@kitsuyui/luxon-ext'

const duration = Duration.fromObject({ hours: 1, minutes: 23, seconds: 45 })
toHumanDurationExtended(duration))  // => '1 hour, 24 minutes'
toHumanDurationWithTemporal(duration, 'past')  // => '1 hour, 24 minutes ago'
toHumanDurationWithTemporal(duration, 'future')  // => 'in 1 hour, 24 minutes'
const date1 = DateTime.fromISO('2024-01-01T00:00:00Z')
const date2 = DateTime.fromISO('2024-01-01T01:23:45Z')
toHumanDurationWithDiff(date1, date2)  // => 'in 1 hour, 24 minutes'

You can pass options same as luxon's toHuman method.

c.f. moment/luxon#1134

This package provides some extensions for Luxon.

```typescript
import { Duration } from 'luxon'
import { toHumanDurationExtended, toHumanDurationWithTemporal, toHumanDurationWithDiff } from '@kitsuyui/luxon-ext'

const duration = Duration.fromObject({ hours: 1, minutes: 23, seconds: 45 })
toHumanDurationExtended(duration))  // => '1 hour, 24 minutes'
toHumanDurationWithTemporal(duration, 'past')  // => '1 hour, 24 minutes ago'
toHumanDurationWithTemporal(duration, 'future')  // => 'in 1 hour, 24 minutes'
const date1 = DateTime.fromISO('2024-01-01T00:00:00Z')
const date2 = DateTime.fromISO('2024-01-01T01:23:45Z')
toHumanDurationWithDiff(date1, date2)  // => 'in 1 hour, 24 minutes'
```

You can pass options same as luxon's `toHuman` method.
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.43%. Comparing base (ea3731f) to head (a835cb5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #225      +/-   ##
==========================================
+ Coverage   97.19%   98.43%   +1.24%     
==========================================
  Files           8       12       +4     
  Lines         107      192      +85     
  Branches       18       40      +22     
==========================================
+ Hits          104      189      +85     
  Misses          3        3              
Flag Coverage Δ
unittests 98.43% <100.00%> (+1.24%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kitsuyui kitsuyui merged commit 8c88396 into main Mar 30, 2024
11 checks passed
@kitsuyui kitsuyui deleted the luxon-ext branch March 30, 2024 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants