Skip to content

Commit

Permalink
Merge branch 'next' into word-any
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Nov 9, 2022
2 parents c172d3b + 666ff02 commit de9f2d6
Show file tree
Hide file tree
Showing 42 changed files with 556 additions and 405 deletions.
1 change: 0 additions & 1 deletion src/locales/ar/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1799
export default {
wide: [
'كَانُون ٱلثَّانِي',
Expand Down
1 change: 0 additions & 1 deletion src/locales/ar/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { DateEntryDefinition } from '../../../definitions';

// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1847
export default {
wide: [
'الأحَد',
Expand Down
1 change: 0 additions & 1 deletion src/locales/az/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/ru.xml#L1734
export default {
wide: [
'yanvar',
Expand Down
1 change: 0 additions & 1 deletion src/locales/az/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/ru.xml#L1825
export default {
wide: [
'Bazar',
Expand Down
1 change: 0 additions & 1 deletion src/locales/cz/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1799
export default {
wide: [
'Leden',
Expand Down
1 change: 0 additions & 1 deletion src/locales/cz/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1847
export default {
wide: ['Pondělí', 'Úterý', 'Středa', 'čtvrtek', 'Pátek', 'Sobota', 'Neděle'],
// Property "wide_context" is optional, if not set then "wide" will be used instead
Expand Down
1 change: 0 additions & 1 deletion src/locales/de/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1799
export default {
wide: [
'Januar',
Expand Down
1 change: 0 additions & 1 deletion src/locales/de/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1847
export default {
wide: [
'Sonntag',
Expand Down
1 change: 0 additions & 1 deletion src/locales/en/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1799
export default {
wide: [
'January',
Expand Down
1 change: 0 additions & 1 deletion src/locales/en/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1847
export default {
wide: [
'Sunday',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/es/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Sources: https://www.unicode.org/cldr/cldr-aux/charts/28/summary/es.html and https://www.wikilengua.org/index.php/Abreviaciones_en_fechas
// Sources: https://www.wikilengua.org/index.php/Abreviaciones_en_fechas
export default {
wide: [
'enero',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/es/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Sources: https://www.unicode.org/cldr/cldr-aux/charts/28/summary/es.html and https://www.wikilengua.org/index.php/Abreviaciones_en_fechas
// Sources: https://www.wikilengua.org/index.php/Abreviaciones_en_fechas
export default {
wide: [
'domingo',
Expand Down
1 change: 0 additions & 1 deletion src/locales/fa/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1847
export default {
wide: ['شنبه', 'یکشنبه', 'دوشنبه', 'سه شنبه', 'چهارشنبه', 'پتچشنبه', 'جمعه'],
wide_context: [
Expand Down
1 change: 0 additions & 1 deletion src/locales/fr/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1799
export default {
wide: [
'Janvier',
Expand Down
1 change: 0 additions & 1 deletion src/locales/fr/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1847
export default {
wide: [
'Dimanche',
Expand Down
1 change: 0 additions & 1 deletion src/locales/fr_CH/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1799
export default {
wide: [
'Janvier',
Expand Down
1 change: 0 additions & 1 deletion src/locales/fr_CH/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1847
export default {
wide: [
'Dimanche',
Expand Down
1 change: 0 additions & 1 deletion src/locales/he/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1799
export default {
wide: [
'ינואר',
Expand Down
1 change: 0 additions & 1 deletion src/locales/he/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1847
export default {
wide: [
'יום ראשון',
Expand Down
1 change: 0 additions & 1 deletion src/locales/hr/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1799
export default {
wide: [
'siječanj',
Expand Down
1 change: 0 additions & 1 deletion src/locales/hr/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1847
export default {
wide: [
'nedjelja',
Expand Down
1 change: 0 additions & 1 deletion src/locales/mk/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1799
export default {
wide: [
'јануари',
Expand Down
1 change: 0 additions & 1 deletion src/locales/mk/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1847
export default {
wide: [
'недела',
Expand Down
1 change: 0 additions & 1 deletion src/locales/nl/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1799
export default {
wide: [
'januari',
Expand Down
1 change: 0 additions & 1 deletion src/locales/nl/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1847
export default {
wide: [
'zondag',
Expand Down
1 change: 0 additions & 1 deletion src/locales/pt_BR/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1799
export default {
wide: [
'Janeiro',
Expand Down
1 change: 0 additions & 1 deletion src/locales/pt_BR/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1847
export default {
wide: ['Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'],
// Property "wide_context" is optional, if not set then "wide" will be used instead
Expand Down
1 change: 0 additions & 1 deletion src/locales/pt_PT/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: https://unicode.org/cldr/trac/browser/trunk/common/main/pt.xml?rev=14409#L1811
export default {
wide: [
'Janeiro',
Expand Down
1 change: 0 additions & 1 deletion src/locales/pt_PT/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: https://unicode.org/cldr/trac/browser/trunk/common/main/pt_PT.xml?rev=14409#L491
export default {
wide: ['Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado', 'Domingo'],
abbr: ['Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb', 'Dom'],
Expand Down
1 change: 0 additions & 1 deletion src/locales/ru/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/ru.xml#L1734
export default {
wide: [
'январь',
Expand Down
1 change: 0 additions & 1 deletion src/locales/ru/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/ru.xml#L1825
export default {
wide: [
'Воскресенье',
Expand Down
1 change: 0 additions & 1 deletion src/locales/sv/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1799
export default {
wide: [
'januari',
Expand Down
1 change: 0 additions & 1 deletion src/locales/sv/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1847
export default {
wide: ['söndag', 'måndag', 'tisdag', 'onsdag', 'torsdag', 'fredag', 'lördag'],
abbr: ['sön', 'mån', 'tis', 'ons', 'tor', 'fre', 'lör'],
Expand Down
1 change: 0 additions & 1 deletion src/locales/vi/date/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1799
export default {
wide: [
'Tháng Giêng',
Expand Down
1 change: 0 additions & 1 deletion src/locales/vi/date/weekday.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1847
export default {
wide: [
'Chủ nhật',
Expand Down
24 changes: 20 additions & 4 deletions src/modules/date/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ export class DateModule {
* @since 2.0.1
*/
past(years?: number, refDate?: string | Date | number): Date {
if (years <= 0) {
throw new FakerError('Years must be greater than 0.');
}

const date = toDate(refDate);
const range = {
min: 1000,
max: (years || 1) * 365 * 24 * 3600 * 1000,
max: (years ?? 1) * 365 * 24 * 3600 * 1000,
};

let past = date.getTime();
Expand All @@ -76,10 +80,14 @@ export class DateModule {
* @since 2.0.1
*/
future(years?: number, refDate?: string | Date | number): Date {
if (years <= 0) {
throw new FakerError('Years must be greater than 0.');
}

const date = toDate(refDate);
const range = {
min: 1000,
max: (years || 1) * 365 * 24 * 3600 * 1000,
max: (years ?? 1) * 365 * 24 * 3600 * 1000,
};

let future = date.getTime();
Expand Down Expand Up @@ -157,10 +165,14 @@ export class DateModule {
* @since 2.0.1
*/
recent(days?: number, refDate?: string | Date | number): Date {
if (days <= 0) {
throw new FakerError('Days must be greater than 0.');
}

const date = toDate(refDate);
const range = {
min: 1000,
max: (days || 1) * 24 * 3600 * 1000,
max: (days ?? 1) * 24 * 3600 * 1000,
};

let future = date.getTime();
Expand All @@ -186,10 +198,14 @@ export class DateModule {
* @since 5.0.0
*/
soon(days?: number, refDate?: string | Date | number): Date {
if (days <= 0) {
throw new FakerError('Days must be greater than 0.');
}

const date = toDate(refDate);
const range = {
min: 1000,
max: (days || 1) * 24 * 3600 * 1000,
max: (days ?? 1) * 24 * 3600 * 1000,
};

let future = date.getTime();
Expand Down
2 changes: 1 addition & 1 deletion src/modules/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class GitModule {
} = {}
): string {
const {
merge = this.faker.datatype.number({ min: 0, max: 4 }) === 0,
merge = this.faker.datatype.boolean({ probability: 0.2 }),
eol = 'CRLF',
refDate,
} = options;
Expand Down
32 changes: 23 additions & 9 deletions test/date.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach, describe, expect, it } from 'vitest';
import { faker } from '../src';
import { faker, FakerError } from '../src';
import { seededTests } from './support/seededRuns';

const converterMap = [
Expand Down Expand Up @@ -130,11 +130,11 @@ describe('date', () => {
expect(date).greaterThanOrEqual(yearsAgo);
});

it('should return a past date when years 0', () => {
it('should throw an error when years = 0', () => {
const refDate = new Date();
const date = faker.date.past(0, refDate.toISOString());

expect(date).lessThan(refDate);
expect(() => faker.date.past(0, refDate.toISOString())).toThrow(
new FakerError('Years must be greater than 0.')
);
});

it.each(converterMap)(
Expand All @@ -158,11 +158,11 @@ describe('date', () => {
expect(date).greaterThan(new Date());
});

it('should return a future date when years 0', () => {
it('should throw an error when years = 0', () => {
const refDate = new Date();
const date = faker.date.future(0, refDate.toISOString());

expect(date).greaterThan(refDate); // date should be after the date given
expect(() => faker.date.future(0, refDate.toISOString())).toThrow(
new FakerError('Years must be greater than 0.')
);
});

it.each(converterMap)(
Expand Down Expand Up @@ -218,6 +218,13 @@ describe('date', () => {
expect(date).lessThanOrEqual(new Date());
});

it('should throw an error when days = 0', () => {
const refDate = new Date();
expect(() => faker.date.recent(0, refDate.toISOString())).toThrow(
new FakerError('Days must be greater than 0.')
);
});

it.each(converterMap)(
'should return a date N days from the recent past, starting from refDate',
(converter) => {
Expand Down Expand Up @@ -249,6 +256,13 @@ describe('date', () => {
expect(date).greaterThanOrEqual(new Date());
});

it('should throw an error when days = 0', () => {
const refDate = new Date();
expect(() => faker.date.soon(0, refDate.toISOString())).toThrow(
new FakerError('Days must be greater than 0.')
);
});

it.each(converterMap)(
'should return a date N days from the recent future, starting from refDate',
(converter) => {
Expand Down
1 change: 0 additions & 1 deletion test/scripts/apidoc/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
*.actuals.json
temp/
Loading

0 comments on commit de9f2d6

Please sign in to comment.