Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@gund/time-slots
Advanced tools
> Small library to generate slots for a date range between a time range with optional interval
Small library to generate slots for a date range between a time range with optional interval
This is a small utility library that allow you to easily generate time slots and also exclude from generated time slots already existing time slots.
It has "zero" dependencies but requires a small set of date functions to operate
which you can provide via DateAdapter
.
And there is already existing date-fns
adapter that you can use out of the box.
$ npm install @gund/time-slots
Optionally install date-fns
if you want to use out of the box provider:
$ npm install date-fns
First make sure to provide a small set of date functions called DateAdapter
that is needed for this library to work:
import { provideDateAdapter } from '@gund/time-slots';
provideDateAdapter(...); // Your DateAdapter is here
Optionally you may import and use existing date-fns
adapter:
import { provideDateAdapter } from '@gund/time-slots';
import { dateFnsAdapter } from '@gund/time-slots/date-adapter/date-fns';
provideDateAdapter(dateFnsAdapter);
You can generate slots for a date range DateRange
between a time range TimeRange
with optional time interval TimeInterval
:
import { generateTimeSlots, DateRange, TimeRange } from '@gund/time-slots';
const slots = generateTimeSlots(
DateRange.fromDates(new Date(2020, 10, 15), new Date(2020, 10, 20)),
TimeRange.fromTimeStrings('9:00', '17:30'),
);
// Now slots will contain array of `TimeRange`
// between 15.11.2020 to 20.11.2020
// with every day from 9am till 5:30pm
console.log(slots);
To slice every day into intervals you can add TimeInterval
argument:
import {
generateTimeSlots,
DateRange,
TimeRange,
TimeInterval,
} from '@gund/time-slots';
const slots = generateTimeSlots(
DateRange.fromDates(new Date(2020, 10, 15), new Date(2020, 10, 16)),
TimeRange.fromTimeStrings('9:00', '17:30'),
TimeInterval.minutes(30),
);
// Now slots will contain array of `TimeRange`
// between 15.11.2020 to 20.11.2020
// with every day sliced in 30 mins intervals from 9am till 5:30pm
console.log(slots);
You can also exclude from an array of slots another array of slots. The exclusion of a slot will happen as long as it intersects with a slot from another array.
import { excludeTimeSlots } from '@gund/time-slots';
const allSlots = [...];
const bookedSlots = [...];
const availableSlots = excludeTimeSlots(allSlots, bookedSlots);
// Result will have only slots from `allSlots` that
// do not intersect with any slots in `bookedSlots`
console.log(availableSlots);
Run nx build
to build the project. The build artifacts will be stored in the dist/
directory. Use the --prod
flag for a production build.
Run nx test
to execute the unit tests via Jest.
Run nx affected:test
to execute the unit tests affected by a change.
Run nx dep-graph
to see a diagram of the dependencies of your projects.
FAQs
> Small library to generate slots for a date range between a time range with optional interval
We found that @gund/time-slots demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.