New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@beyonk/date-utils

Package Overview
Dependencies
Maintainers
6
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@beyonk/date-utils - npm Package Compare versions

Comparing version 4.4.1 to 4.5.0

17

lib/iso-dates.js

@@ -5,3 +5,4 @@ import {

minsToTime,
ymdNoTimezone as toISODateString
ymdNoTimezone as toISODateString,
utcDate
} from './date-utils.js'

@@ -25,5 +26,17 @@

function toStartDate (iso) {
const { date, timeslot } = fromISOString(iso)
return utcDate(date).add(timeslot, 'minutes').toDate()
}
function toEndDate (iso) {
const { duration } = fromISOString(iso)
return utcDate(toStartDate(iso)).add(duration, 'minutes').toDate()
}
export {
fromISOString,
toISOString
toISOString,
toStartDate,
toEndDate
}

86

lib/iso-dates.spec.js
import { expect } from '@hapi/code'
import { toISOString } from './iso-dates.js'
import { toISOString, fromISOString, toStartDate, toEndDate } from './iso-dates.js'
describe('iso-dates', () => {
const scenarios = [
{
ctx: 'from Date object',
date: new Date('2021-10-31T00:00:00.000Z'),
timeslot: 540,
duration: 90
},
{
ctx: 'from Date string',
date: '2021-10-31',
timeslot: 540,
duration: 90
context('#toISOString()', () => {
const scenarios = [
{
ctx: 'from Date object',
date: new Date('2021-10-31T00:00:00.000Z'),
timeslot: 540,
duration: 90
},
{
ctx: 'from Date string',
date: '2021-10-31',
timeslot: 540,
duration: 90
}
]
for (const { ctx, date, timeslot, duration } of scenarios) {
context(ctx, () => {
it('returns expected string', () => {
expect(
toISOString(date, timeslot, duration)
).to.equal(
'2021-10-31T09:00--PT90M'
)
})
})
}
]
})
for (const { ctx, date, timeslot, duration } of scenarios) {
context(ctx, () => {
it('returns expected string', () => {
describe('#fromISOString()', () => {
const scenarios = [
{ test: 'relative time', value: '2021-10-31T01:15--PT1H30M' },
{ test: 'UTC time', value: '2021-10-31T01:15Z--PT1H30M' },
{ test: 'UTC offset', value: '2021-10-31T01:15-05:00--PT1H30M' }
]
for (const { test, value } of scenarios) {
it(`extracts local date, timeslot and duration elements (${test})`, () => {
expect(
toISOString(date, timeslot, duration)
).to.equal(
'2021-10-31T09:00--PT90M'
)
fromISOString(value)
).to.equal({
date: '2021-10-31',
timeslot: 75,
duration: 90
})
})
}
})
describe('#toStartDate()', () => {
it('returns date', () => {
expect(
toStartDate('2021-10-31T01:15Z--PT1H30M')
).to.equal(
new Date('2021-10-31T01:15Z')
)
})
}
})
describe('#toEndDate()', () => {
it('returns date', () => {
expect(
toEndDate('2021-10-31T01:15Z--PT1H30M')
).to.equal(
new Date('2021-10-31T02:45Z')
)
})
})
})
{
"name": "@beyonk/date-utils",
"version": "4.4.1",
"version": "4.5.0",
"description": "Beyonk Date Utils",

@@ -5,0 +5,0 @@ "author": "Antony Jones <aj@desirableobjects.co.uk>",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc