Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tutitoos committed Jul 23, 2023
1 parent 6c0a4d8 commit 72e4b83
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 73 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"build": "tsc",
"start": "node dist/index.js",
"dev": "ts-node-dev --respawn --transpile-only --poll src/index.ts",
"test": "npm run build && node dist/tests.js",
"test": "node tests.cjs",
"lint": "npm run lint:rome && npm run lint:eslint",
"lint:rome": "rome check src",
"lint:eslint": "eslint --ignore-path .gitignore . --max-warnings 0",
Expand Down
13 changes: 11 additions & 2 deletions src/Validate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { type GetTime, type GetNextTime, type GetFormatDate, type GetDate, type GetCompareDate } from "./types";
import type { DateFormats, DateTypes, Locales, Timezones } from "./types/global";
import {
type GetTime,
type GetNextTime,
type GetFormatDate,
type GetDate,
type GetCompareDate,
type DateFormats,
type DateTypes,
type Locales,
type Timezones,
} from "./types";

class Validate {
/**
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

import * as utilTiempo from "./lib/index";

module.exports = utilTiempo;
export default utilTiempo;
export * from "./lib/index";
2 changes: 1 addition & 1 deletion src/lib/get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Validate from "../Validate";
import type { DateTypes } from "../types/global";
import type { DateTypes } from "../types";
import { dateList } from "../util";

/**
Expand Down
3 changes: 1 addition & 2 deletions src/lib/getCompareDate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Validate from "../Validate";
import type { GetCompareDateProps } from "../types";
import { type DateNameAliases } from "../types/global";
import type { GetCompareDateProps, DateNameAliases } from "../types";
import { compareDataParse, dateList } from "../util";

/**
Expand Down
3 changes: 1 addition & 2 deletions src/lib/getFormatDate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Validate from "../Validate";
import type { GetFormatDateProps } from "../types";
import type { HourFormats, TimeFormats } from "../types/global";
import type { GetFormatDateProps, HourFormats, TimeFormats } from "../types";

/**
* Returns a formatted date string based on the provided options.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/getMs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Validate from "../Validate";
import type { DateTypes } from "../types/global";
import type { DateTypes } from "../types";
import { dateList } from "../util";

/**
Expand Down
47 changes: 47 additions & 0 deletions src/types/global.d.ts → src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
export interface GetTime {
timestamp?: number | null;
local?: Locales;
timezone?: Timezones;
hour12?: boolean;
}
export type GetTimeProps = GetTime[] | [GetTime["timestamp"], GetTime["local"], GetTime["timezone"], GetTime["hour12"]];

export interface GetDate {
timestamp?: number | null;
local?: Locales;
timezone?: Timezones;
}
export type GetDateProps = GetDate[] | [GetDate["timestamp"], GetDate["local"], GetDate["timezone"]];

export interface GetCompareDate {
timestamp1?: number;
timestamp2?: number | null;
format?: DateFormats;
}
export type GetCompareDateProps =
| GetCompareDate[]
| [GetCompareDate["timestamp1"], GetCompareDate["timestamp2"], GetCompareDate["format"]];

export interface GetFormatDate {
timestamp?: number;
format?: string;
local?: Locales;
timezone?: Timezones;
hour12?: boolean;
}
export type GetFormatDateProps =
| GetFormatDate[]
| [
GetFormatDate["timestamp"],
GetFormatDate["format"],
GetFormatDate["local"],
GetFormatDate["timezone"],
GetFormatDate["hour12"]
];

export interface GetNextTime {
time?: string;
timezone?: Timezones;
}
export type GetNextTimeProps = GetNextTime[] | [GetNextTime["time"], GetNextTime["timezone"]];

export type DateFormats = "long" | "short";
export type HourFormats = "hourLong" | "hourShort";
export type TimeFormats =
Expand Down
48 changes: 0 additions & 48 deletions src/types/index.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DateFormats, DateList, DateOptions } from "./types/global";
import type { DateFormats, DateList, DateOptions } from "./types";

/**
* List of date units with their properties.
Expand Down
58 changes: 47 additions & 11 deletions src/tests.ts → tests.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import utilTiempo from "./index";
const utilTiempo = require("./dist/index");

const runTestGet = true;
const runTestGetCompareDate = true;
Expand All @@ -24,9 +24,18 @@ if (runTestGetCompareDate) {
console.log("===============[GET_COMPARE_DATE]===============");
console.log("[TEST 1] (empty) => ", utilTiempo.getCompareDate());
console.log("[TEST 2] (1000) => ", utilTiempo.getCompareDate(1000));
console.log("[TEST 3] (1000, 5000) => ", utilTiempo.getCompareDate(1000, 5000));
console.log("[TEST 4] (1000, 5000, 'long') => ", utilTiempo.getCompareDate(1000, 5000, "long"));
console.log("[TEST 5] (1000, 5000, 'short') => ", utilTiempo.getCompareDate(1000, 5000, "short"));
console.log(
"[TEST 3] (1000, 5000) => ",
utilTiempo.getCompareDate(1000, 5000)
);
console.log(
"[TEST 4] (1000, 5000, 'long') => ",
utilTiempo.getCompareDate(1000, 5000, "long")
);
console.log(
"[TEST 5] (1000, 5000, 'short') => ",
utilTiempo.getCompareDate(1000, 5000, "short")
);
console.log(
"[TEST 6] ({timestamp1: 1000,timestamp2: 5000,format: 'long'}) => ",
utilTiempo.getCompareDate({
Expand All @@ -48,7 +57,10 @@ if (runTestGetCompareDate) {
if (runTestGetDate) {
console.log("===============[GET_DATE]===============");
console.log("[TEST 1] (empty) => ", utilTiempo.getDate());
console.log("[TEST 2] (1683299105000) => ", utilTiempo.getDate(1683299105000));
console.log(
"[TEST 2] (1683299105000) => ",
utilTiempo.getDate(1683299105000)
);
console.log(
"[TEST 3] (1683299105000, 'es-ES', 'Europe/Madrid') => ",
utilTiempo.getDate(1683299105000, "es-ES", "Europe/Madrid")
Expand All @@ -66,14 +78,29 @@ if (runTestGetDate) {
if (runTestGetFormatDate) {
console.log("===============[GET_FORMAT_DATE]===============");
console.log("[TEST 1]", utilTiempo.getFormatDate());
console.log("[TEST 2] (1683299105000)", utilTiempo.getFormatDate(1683299105000));
console.log(
"[TEST 2] (1683299105000)",
utilTiempo.getFormatDate(1683299105000)
);
console.log(
"[TEST 3] (1683299105000, '{DD}/{MM}/{YYYY} {hh}:{mm}:{ss} {apm}', 'es-ES', 'Europe/Madrid', true) => ",
utilTiempo.getFormatDate(1683299105000, "{DD}/{MM}/{YYYY} {hh}:{mm}:{ss} {apm}", "es-ES", "Europe/Madrid", true)
utilTiempo.getFormatDate(
1683299105000,
"{DD}/{MM}/{YYYY} {hh}:{mm}:{ss} {apm}",
"es-ES",
"Europe/Madrid",
true
)
);
console.log(
"[TEST 4] (1683299105000, '{DD}/{MM}/{YYYY} {hh}:{mm}:{ss} {apm}', 'es-ES', 'Europe/Madrid', false) => ",
utilTiempo.getFormatDate(1683299105000, "{DD}/{MM}/{YYYY} {hh}:{mm}:{ss} {apm}", "es-ES", "Europe/Madrid", false)
utilTiempo.getFormatDate(
1683299105000,
"{DD}/{MM}/{YYYY} {hh}:{mm}:{ss} {apm}",
"es-ES",
"Europe/Madrid",
false
)
);
console.log(
"[TEST 5] ({timestamp: 1683299105000, format: '{DD}/{MM}/{YYYY} {hh}:{mm}:{ss} {apm}', local: 'es-ES', timezone: 'Europe/Madrid', hour12: true}) => ",
Expand Down Expand Up @@ -106,13 +133,19 @@ if (runTestGetMs) {
console.log("[TEST 5] ('1hour') => ", utilTiempo.getMs("1hour"));
console.log("[TEST 6] ('1minute') => ", utilTiempo.getMs("1minute"));
console.log("[TEST 7] ('1second') => ", utilTiempo.getMs("1second"));
console.log("[TEST 8] ('1millisecond') => ", utilTiempo.getMs("1millisecond"));
console.log(
"[TEST 8] ('1millisecond') => ",
utilTiempo.getMs("1millisecond")
);
}

if (runTestGetTime) {
console.log("===============[GET_TIME]===============");
console.log("[TEST 1] (empty) => ", utilTiempo.getTime());
console.log("[TEST 2] (1683299105000) => ", utilTiempo.getTime(1683299105000));
console.log(
"[TEST 2] (1683299105000) => ",
utilTiempo.getTime(1683299105000)
);
console.log(
"[TEST 3] (1683299105000, 'es-ES', 'Europe/Madrid', true) => ",
utilTiempo.getTime(1683299105000, "es-ES", "Europe/Madrid", true)
Expand Down Expand Up @@ -144,7 +177,10 @@ if (runTestGetTime) {
if (runTestGetNextTime) {
console.log("===============[GET_NEXT_TIME]===============");
console.log("[TEST 1] ('10:00:00') => ", utilTiempo.getNextTime("10:00:00"));
console.log("[TEST 2] ('10:00:00', 'Europe/Madrid') => ", utilTiempo.getNextTime("10:00:00", "Europe/Madrid"));
console.log(
"[TEST 2] ('10:00:00', 'Europe/Madrid') => ",
utilTiempo.getNextTime("10:00:00", "Europe/Madrid")
);
console.log(
"[TEST 3] ({time: '10:00:00', timezone: 'Europe/Madrid'}) => ",
utilTiempo.getNextTime({
Expand Down
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
"esModuleInterop": true,
"outDir": "dist",
"declaration": true,
"declarationDir": "dist",
"noEmitOnError": true,
"forceConsistentCasingInFileNames": true,
"noImplicitAny": true,
"strictNullChecks": true
},
"include": [
"src/**/*.ts"
]
"src/**/*.ts",
],
}

0 comments on commit 72e4b83

Please sign in to comment.