Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,16 @@ Zips given arrays together with the given function.

#### debounce

Makes the function run after the given period of not being called. Useful to delay input submission for autocomplete etc.

#### delay

When awaited, delays the execution by the given number of milliseconds.

#### sequence

Runs the given tasks in a sequence.

### date

#### byDateWithFallback
Expand All @@ -210,12 +216,18 @@ Zips given arrays together with the given function.

#### dateDiff

Calculates the difference in milliseconds between two dates.

#### dateInRange

Checks if provided date is within the range.

#### dayRange

#### daysInMonths

Returns numbers of days in all months of the year having regard to leap year.

#### daysInYear

#### displayMonth
Expand All @@ -224,6 +236,8 @@ Zips given arrays together with the given function.

#### endOfDay

Calculates end of a day in provided date.

#### formatDate

#### formatDateTime
Expand All @@ -248,6 +262,8 @@ Zips given arrays together with the given function.

#### monthNames

Returns all months names.

#### offsetByBit

#### parseHourMinutePair
Expand All @@ -256,6 +272,8 @@ Zips given arrays together with the given function.

#### startOfDay

Calculates start of a day in provided date.

#### subtractDays

#### toDate
Expand Down
6 changes: 6 additions & 0 deletions async/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# debounce

Makes the function run after the given period of not being called. Useful to delay input submission for autocomplete etc.

# delay

When awaited, delays the execution by the given number of milliseconds.

# sequence

Runs the given tasks in a sequence.
2 changes: 2 additions & 0 deletions async/debounce.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# debounce

Makes the function run after the given period of not being called. Useful to delay input submission for autocomplete etc.
2 changes: 2 additions & 0 deletions async/delay.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# delay

When awaited, delays the execution by the given number of milliseconds.
12 changes: 5 additions & 7 deletions async/sequence.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
export default async tasks => {
const results = tasks.map(() => undefined);
await tasks.reduce((chain, current, i) => {
return chain.then(() =>
current().then(x => {
results[i] = x;
await tasks.reduce(async (chain, current, i) => {
await chain;
const x = await current();
results[i] = x;

return x;
})
);
return x;
}, Promise.resolve());

return results;
Expand Down
2 changes: 2 additions & 0 deletions async/sequence.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# sequence

Runs the given tasks in a sequence.
12 changes: 12 additions & 0 deletions date/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

# dateDiff

Calculates the difference in milliseconds between two dates.

# dateInRange

Checks if provided date is within the range.

# dayRange

# daysInMonths

Returns numbers of days in all months of the year having regard to leap year.

# daysInYear

# displayMonth
Expand All @@ -18,6 +24,8 @@

# endOfDay

Calculates end of a day in provided date.

# formatDate

# formatDateTime
Expand All @@ -42,6 +50,8 @@

# monthNames

Returns all months names.

# offsetByBit

# parseHourMinutePair
Expand All @@ -50,6 +60,8 @@

# startOfDay

Calculates start of a day in provided date.

# subtractDays

# toDate
Expand Down
2 changes: 1 addition & 1 deletion date/dateDiff.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dateDiff",
"description": "TODO: Fill short description here.",
"description": "Calculates the difference in milliseconds between two dates.",
"signature": "TODO: Fill type signature here.",
"examples": [
{
Expand Down
2 changes: 2 additions & 0 deletions date/dateDiff.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# dateDiff

Calculates the difference in milliseconds between two dates.
18 changes: 16 additions & 2 deletions date/dateDiff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@
import dateDiff from "./dateDiff.ts";

describe("dateDiff", () => {
it.skip("TODO", () => {
expect(dateDiff()).toBeDefined();
it("returns the difference of 24 hours in miliseconds", () => {
const firstDate = new Date("2019-12-18T12:00:00");
const secondDate = new Date("2019-12-17T12:00:00");

const dayInMiliseconds = 86400000;

expect(dateDiff(firstDate, secondDate)).toEqual(dayInMiliseconds);
});

it("returns 0 difference of eqact same dates", () => {
const firstDate = new Date("2019-10-10T10:00:00");
const secondDate = new Date("2019-10-10T10:00:00");

const noDifference = 0;

expect(dateDiff(firstDate, secondDate)).toEqual(noDifference);
});
});
2 changes: 1 addition & 1 deletion date/dateDiff.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default (a, b) => {
export default (a: string | Date, b: string | Date): number => {
const d1 = new Date(a);
const d2 = new Date(b);

Expand Down
2 changes: 1 addition & 1 deletion date/dateInRange.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dateInRange",
"description": "TODO: Fill short description here.",
"description": "Checks if provided date is within the range.",
"signature": "TODO: Fill type signature here.",
"examples": [
{
Expand Down
2 changes: 2 additions & 0 deletions date/dateInRange.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# dateInRange

Checks if provided date is within the range.
20 changes: 18 additions & 2 deletions date/dateInRange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@
import dateInRange from "./dateInRange.ts";

describe("dateInRange", () => {
it.skip("TODO", () => {
expect(dateInRange()).toBeDefined();
it("provided date is within the day range", () => {
const startRangeDate = new Date("2019-05-28T12:00:00");
const endRangeDate = new Date("2019-05-29T12:00:00");
const dateToCheck = new Date("2019-05-28T24:00:00");

expect(dateInRange(startRangeDate, endRangeDate)(dateToCheck)).toEqual(
true
);
});

it("provided date is not within the year range", () => {
const startRangeDate = new Date("2018-05-28T12:00:00");
const endRangeDate = new Date("2019-05-29T12:00:00");
const dateToCheck = new Date("2017-05-28T24:00:00");

expect(dateInRange(startRangeDate, endRangeDate)(dateToCheck)).toEqual(
false
);
});
});
4 changes: 3 additions & 1 deletion date/dateInRange.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default (from, to) => (date = new Date()) => {
export default (from: string | Date, to: string | Date) => (
date = new Date()
): boolean => {
const dateTime = new Date(date).getTime();
const fromTime = new Date(from).getTime();
const toTime = new Date(to).getTime();
Expand Down
2 changes: 1 addition & 1 deletion date/daysInMonths.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "daysInMonths",
"description": "TODO: Fill short description here.",
"description": "Returns numbers of days in all months of the year having regard to leap year.",
"signature": "TODO: Fill type signature here.",
"examples": [
{
Expand Down
2 changes: 2 additions & 0 deletions date/daysInMonths.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# daysInMonths

Returns numbers of days in all months of the year having regard to leap year.
42 changes: 40 additions & 2 deletions date/daysInMonths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,45 @@
import daysInMonths from "./daysInMonths.ts";

describe("daysInMonths", () => {
it.skip("TODO", () => {
expect(daysInMonths()).toBeDefined();
it("returns number of days in a months in a leap year", () => {
const leapYear = true;

const numberOfDaysInMonthsInLeapYear = [
31,
29,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
];

expect(daysInMonths(leapYear)).toEqual(numberOfDaysInMonthsInLeapYear);
});

it("returns number of days in a months in a year", () => {
const leapYear = false;

const numberOfDaysInMonths = [
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
];

expect(daysInMonths(leapYear)).toEqual(numberOfDaysInMonths);
});
});
2 changes: 1 addition & 1 deletion date/daysInMonths.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default leapYear => [
export default (leapYear): number[] => [
31,
leapYear ? 29 : 28,
31,
Expand Down
2 changes: 1 addition & 1 deletion date/endOfDay.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "endOfDay",
"description": "TODO: Fill short description here.",
"description": "Calculates end of a day in provided date.",
"signature": "TODO: Fill type signature here.",
"examples": [
{
Expand Down
2 changes: 2 additions & 0 deletions date/endOfDay.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# endOfDay

Calculates end of a day in provided date.
19 changes: 17 additions & 2 deletions date/endOfDay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
import endOfDay from "./endOfDay.ts";

describe("endOfDay", () => {
it.skip("TODO", () => {
expect(endOfDay()).toBeDefined();
const date = new Date("2018-12-31T13:54:33.232Z");

it("should handle timezone offsets", () => {
const localOffset = -180;

const end = endOfDay(date, localOffset);
const expectedUTC = new Date("2019-01-01T03:00:00.000Z");
const expectedLocal = new Date("2018-12-31T24:00:00.000-03:00");

expect(end).toEqual(expectedUTC);
expect(end).toEqual(expectedLocal);
});

it("should handle default local date time display", () => {
const localOffset = 0;

expect(endOfDay(date)).toEqual(endOfDay(date, localOffset));
});
});
6 changes: 5 additions & 1 deletion date/endOfDay.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import toLocalDateTime from "./toLocalDateTime";

export default (date, timezoneOffset = 0, local = true) => {
export default (
date: string | Date,
timezoneOffset = 0,
local = true
): Date => {
const newDate = new Date(date);
newDate.setHours(24, 0, 0, 0);

Expand Down
2 changes: 1 addition & 1 deletion date/monthNames.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default [
export default () => [
"January",
"February",
"March",
Expand Down
2 changes: 1 addition & 1 deletion date/monthNames.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monthNames",
"description": "TODO: Fill short description here.",
"description": "Returns all months names.",
"signature": "TODO: Fill type signature here.",
"examples": [
{
Expand Down
2 changes: 2 additions & 0 deletions date/monthNames.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# monthNames

Returns all months names.
19 changes: 17 additions & 2 deletions date/monthNames.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
import monthNames from "./monthNames.ts";

describe("monthNames", () => {
it.skip("TODO", () => {
expect(monthNames()).toBeDefined();
it("Returns all month names", () => {
const allMonthNames = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
];

expect(monthNames()).toEqual(allMonthNames);
});
});
Loading