mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-18 13:39:31 +02:00
Merge pull request #167 from AshAnand34/crontab-guru-tool
Crontab guru tool
This commit is contained in:
303
.idea/workspace.xml
generated
303
.idea/workspace.xml
generated
@@ -4,11 +4,10 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="chore: add array key">
|
||||
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="fix:">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/Hero.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/Hero.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools-by-category/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools-by-category/index.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/utils/string.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/utils/string.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools/time/crontab-guru/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/time/crontab-guru/index.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools/time/crontab-guru/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/time/crontab-guru/meta.ts" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -41,178 +40,178 @@
|
||||
"state": "OPEN"
|
||||
}
|
||||
}</component>
|
||||
<component name="GitHubPullRequestState"><![CDATA[{
|
||||
"prStates": [
|
||||
<component name="GitHubPullRequestState">{
|
||||
"prStates": [
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts51PkS9",
|
||||
"number": 22
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts51PkS9",
|
||||
"number": 22
|
||||
},
|
||||
"lastSeen": 1741207144695
|
||||
"lastSeen": 1741207144695
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6NiNYl",
|
||||
"number": 32
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6NiNYl",
|
||||
"number": 32
|
||||
},
|
||||
"lastSeen": 1741209723869
|
||||
"lastSeen": 1741209723869
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6Nheyd",
|
||||
"number": 31
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6Nheyd",
|
||||
"number": 31
|
||||
},
|
||||
"lastSeen": 1741213371410
|
||||
"lastSeen": 1741213371410
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6NmRBs",
|
||||
"number": 33
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6NmRBs",
|
||||
"number": 33
|
||||
},
|
||||
"lastSeen": 1741282429036
|
||||
"lastSeen": 1741282429036
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts5zyFTs",
|
||||
"number": 15
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts5zyFTs",
|
||||
"number": 15
|
||||
},
|
||||
"lastSeen": 1741535540953
|
||||
"lastSeen": 1741535540953
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QQB3c",
|
||||
"number": 59
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QQB3c",
|
||||
"number": 59
|
||||
},
|
||||
"lastSeen": 1743018960900
|
||||
"lastSeen": 1743018960900
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QMPEg",
|
||||
"number": 58
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QMPEg",
|
||||
"number": 58
|
||||
},
|
||||
"lastSeen": 1743019452983
|
||||
"lastSeen": 1743019452983
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QZvRI",
|
||||
"number": 61
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QZvRI",
|
||||
"number": 61
|
||||
},
|
||||
"lastSeen": 1743103196866
|
||||
"lastSeen": 1743103196866
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QqPrQ",
|
||||
"number": 73
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QqPrQ",
|
||||
"number": 73
|
||||
},
|
||||
"lastSeen": 1743265865001
|
||||
"lastSeen": 1743265865001
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6Qp5nI",
|
||||
"number": 72
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6Qp5nI",
|
||||
"number": 72
|
||||
},
|
||||
"lastSeen": 1743338472110
|
||||
"lastSeen": 1743338472110
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QsjlS",
|
||||
"number": 76
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QsjlS",
|
||||
"number": 76
|
||||
},
|
||||
"lastSeen": 1743352150953
|
||||
"lastSeen": 1743352150953
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6Q0JBe",
|
||||
"number": 82
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6Q0JBe",
|
||||
"number": 82
|
||||
},
|
||||
"lastSeen": 1743470267269
|
||||
"lastSeen": 1743470267269
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6UE9-x",
|
||||
"number": 102
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6UE9-x",
|
||||
"number": 102
|
||||
},
|
||||
"lastSeen": 1747171977348
|
||||
"lastSeen": 1747171977348
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6XPua_",
|
||||
"number": 117
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6XPua_",
|
||||
"number": 117
|
||||
},
|
||||
"lastSeen": 1747929835864
|
||||
"lastSeen": 1747929835864
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6XY-mZ",
|
||||
"number": 119
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6XY-mZ",
|
||||
"number": 119
|
||||
},
|
||||
"lastSeen": 1748028108508
|
||||
"lastSeen": 1748028108508
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6Xdz4n",
|
||||
"number": 120
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6Xdz4n",
|
||||
"number": 120
|
||||
},
|
||||
"lastSeen": 1748282672214
|
||||
"lastSeen": 1748282672214
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6X_zxl",
|
||||
"number": 131
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6X_zxl",
|
||||
"number": 131
|
||||
},
|
||||
"lastSeen": 1748881279494
|
||||
"lastSeen": 1748881279494
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6bhieT",
|
||||
"number": 152
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6bhieT",
|
||||
"number": 152
|
||||
},
|
||||
"lastSeen": 1751848489082
|
||||
"lastSeen": 1751848489082
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6dOyRk",
|
||||
"number": 154
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6dOyRk",
|
||||
"number": 154
|
||||
},
|
||||
"lastSeen": 1751849436454
|
||||
"lastSeen": 1751849436454
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6cHjNi",
|
||||
"number": 153
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6cHjNi",
|
||||
"number": 153
|
||||
},
|
||||
"lastSeen": 1751849501498
|
||||
"lastSeen": 1751849501498
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6Zs1FN",
|
||||
"number": 145
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6Zs1FN",
|
||||
"number": 145
|
||||
},
|
||||
"lastSeen": 1751849770308
|
||||
"lastSeen": 1751849770308
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6bgKi9",
|
||||
"number": 150
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6bgKi9",
|
||||
"number": 150
|
||||
},
|
||||
"lastSeen": 1751850367300
|
||||
"lastSeen": 1751850367300
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6dv21R",
|
||||
"number": 162
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6dv21R",
|
||||
"number": 162
|
||||
},
|
||||
"lastSeen": 1751893739514
|
||||
"lastSeen": 1751893739514
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6dwQJi",
|
||||
"number": 163
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6dwQJi",
|
||||
"number": 163
|
||||
},
|
||||
"lastSeen": 1751893861615
|
||||
"lastSeen": 1751893861615
|
||||
}
|
||||
]
|
||||
}]]></component>
|
||||
}</component>
|
||||
<component name="GithubPullRequestsUISettings">{
|
||||
"selectedUrlAndAccountId": {
|
||||
"url": "https://github.com/iib0011/omni-tools.git",
|
||||
@@ -244,56 +243,56 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"ASKED_ADD_EXTERNAL_FILES": "true",
|
||||
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"Docker.Dockerfile build.executor": "Run",
|
||||
"Docker.Dockerfile.executor": "Run",
|
||||
"Playwright.Create transparent PNG.should make png color transparent.executor": "Run",
|
||||
"Playwright.JoinText Component.executor": "Run",
|
||||
"Playwright.JoinText Component.should merge text pieces with specified join character.executor": "Run",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"Vitest.compute function (1).executor": "Run",
|
||||
"Vitest.compute function.executor": "Run",
|
||||
"Vitest.mergeText.executor": "Run",
|
||||
"Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false.executor": "Run",
|
||||
"Vitest.mergeText.should merge lines, preserve blank lines and trailing spaces when both deleteBlankLines and deleteTrailingSpaces are false.executor": "Run",
|
||||
"Vitest.parsePageRanges.executor": "Run",
|
||||
"Vitest.removeDuplicateLines function.executor": "Run",
|
||||
"Vitest.removeDuplicateLines function.newlines option.executor": "Run",
|
||||
"Vitest.removeDuplicateLines function.newlines option.should filter newlines when newlines is set to filter.executor": "Run",
|
||||
"Vitest.replaceText function (regexp mode).should return the original text when passed an invalid regexp.executor": "Run",
|
||||
"Vitest.replaceText function.executor": "Run",
|
||||
"Vitest.timeBetweenDates.executor": "Run",
|
||||
"git-widget-placeholder": "#163 on fork/y1hao/grouping",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "C:/Users/Ibrahima/IdeaProjects/omni-tools/src/pages/tools/json",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"npm.build.executor": "Run",
|
||||
"npm.dev.executor": "Run",
|
||||
"npm.lint.executor": "Run",
|
||||
"npm.prebuild.executor": "Run",
|
||||
"npm.script:create:tool.executor": "Run",
|
||||
"npm.test.executor": "Run",
|
||||
"npm.test:e2e.executor": "Run",
|
||||
"npm.test:e2e:run.executor": "Run",
|
||||
"prettierjs.PrettierConfiguration.Package": "C:\\Users\\Ibrahima\\IdeaProjects\\omni-tools\\node_modules\\prettier",
|
||||
"project.structure.last.edited": "Problems",
|
||||
"project.structure.proportion": "0.0",
|
||||
"project.structure.side.proportion": "0.2",
|
||||
"settings.editor.selected.configurable": "refactai_advanced_settings",
|
||||
"ts.external.directory.path": "C:\\Users\\Ibrahima\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"ASKED_ADD_EXTERNAL_FILES": "true",
|
||||
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"Docker.Dockerfile build.executor": "Run",
|
||||
"Docker.Dockerfile.executor": "Run",
|
||||
"Playwright.Create transparent PNG.should make png color transparent.executor": "Run",
|
||||
"Playwright.JoinText Component.executor": "Run",
|
||||
"Playwright.JoinText Component.should merge text pieces with specified join character.executor": "Run",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"Vitest.compute function (1).executor": "Run",
|
||||
"Vitest.compute function.executor": "Run",
|
||||
"Vitest.mergeText.executor": "Run",
|
||||
"Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false.executor": "Run",
|
||||
"Vitest.mergeText.should merge lines, preserve blank lines and trailing spaces when both deleteBlankLines and deleteTrailingSpaces are false.executor": "Run",
|
||||
"Vitest.parsePageRanges.executor": "Run",
|
||||
"Vitest.removeDuplicateLines function.executor": "Run",
|
||||
"Vitest.removeDuplicateLines function.newlines option.executor": "Run",
|
||||
"Vitest.removeDuplicateLines function.newlines option.should filter newlines when newlines is set to filter.executor": "Run",
|
||||
"Vitest.replaceText function (regexp mode).should return the original text when passed an invalid regexp.executor": "Run",
|
||||
"Vitest.replaceText function.executor": "Run",
|
||||
"Vitest.timeBetweenDates.executor": "Run",
|
||||
"git-widget-placeholder": "#167 on fork/AshAnand34/crontab-guru-tool",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "C:/Users/Ibrahima/IdeaProjects/omni-tools/src/pages/tools/json",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"npm.build.executor": "Run",
|
||||
"npm.dev.executor": "Run",
|
||||
"npm.lint.executor": "Run",
|
||||
"npm.prebuild.executor": "Run",
|
||||
"npm.script:create:tool.executor": "Run",
|
||||
"npm.test.executor": "Run",
|
||||
"npm.test:e2e.executor": "Run",
|
||||
"npm.test:e2e:run.executor": "Run",
|
||||
"prettierjs.PrettierConfiguration.Package": "C:\\Users\\Ibrahima\\IdeaProjects\\omni-tools\\node_modules\\prettier",
|
||||
"project.structure.last.edited": "Problems",
|
||||
"project.structure.proportion": "0.0",
|
||||
"project.structure.side.proportion": "0.2",
|
||||
"settings.editor.selected.configurable": "refactai_advanced_settings",
|
||||
"ts.external.directory.path": "C:\\Users\\Ibrahima\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
}
|
||||
}]]></component>
|
||||
}</component>
|
||||
<component name="ReactDesignerToolWindowState">
|
||||
<option name="myId2Visible">
|
||||
<map>
|
||||
|
17
package-lock.json
generated
17
package-lock.json
generated
@@ -26,6 +26,8 @@
|
||||
"browser-image-compression": "^2.0.2",
|
||||
"buffer": "^6.0.3",
|
||||
"color": "^4.2.3",
|
||||
"cron-validator": "^1.3.1",
|
||||
"cronstrue": "^3.0.0",
|
||||
"dayjs": "^1.11.13",
|
||||
"formik": "^2.4.6",
|
||||
"jimp": "^0.22.12",
|
||||
@@ -4819,6 +4821,21 @@
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/cron-validator": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/cron-validator/-/cron-validator-1.3.1.tgz",
|
||||
"integrity": "sha512-C1HsxuPCY/5opR55G5/WNzyEGDWFVG+6GLrA+fW/sCTcP6A6NTjUP2AK7B8n2PyFs90kDG2qzwm8LMheADku6A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/cronstrue": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cronstrue/-/cronstrue-3.0.0.tgz",
|
||||
"integrity": "sha512-acwNTPzndJUmfDmcUN2cpBH4EgVn30rg5BYDAP8n5ENPP8A3IH2Z0UbxaNjvCkKxccjtfsTVhF6d+eHhv/GK5g==",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"cronstrue": "bin/cli.js"
|
||||
}
|
||||
},
|
||||
"node_modules/cross-spawn": {
|
||||
"version": "7.0.3",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
|
||||
|
@@ -43,6 +43,8 @@
|
||||
"browser-image-compression": "^2.0.2",
|
||||
"buffer": "^6.0.3",
|
||||
"color": "^4.2.3",
|
||||
"cron-validator": "^1.3.1",
|
||||
"cronstrue": "^3.0.0",
|
||||
"dayjs": "^1.11.13",
|
||||
"formik": "^2.4.6",
|
||||
"jimp": "^0.22.12",
|
||||
|
@@ -7,11 +7,13 @@ import InputFooter from './InputFooter';
|
||||
export default function ToolTextInput({
|
||||
value,
|
||||
onChange,
|
||||
title = 'Input text'
|
||||
title = 'Input text',
|
||||
placeholder
|
||||
}: {
|
||||
title?: string;
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
placeholder?: string;
|
||||
}) {
|
||||
const { showSnackBar } = useContext(CustomSnackBarContext);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
@@ -50,6 +52,7 @@ export default function ToolTextInput({
|
||||
fullWidth
|
||||
multiline
|
||||
rows={10}
|
||||
placeholder={placeholder}
|
||||
sx={{
|
||||
'&.MuiTextField-root': {
|
||||
backgroundColor: 'background.paper'
|
||||
|
@@ -0,0 +1,26 @@
|
||||
import { expect, describe, it } from 'vitest';
|
||||
import { validateCrontab, explainCrontab } from './service';
|
||||
|
||||
describe('crontab-guru service', () => {
|
||||
it('validates correct crontab expressions', () => {
|
||||
expect(validateCrontab('35 16 * * 0-5')).toBe(true);
|
||||
expect(validateCrontab('* * * * *')).toBe(true);
|
||||
expect(validateCrontab('0 12 1 * *')).toBe(true);
|
||||
});
|
||||
|
||||
it('invalidates incorrect crontab expressions', () => {
|
||||
expect(validateCrontab('invalid expression')).toBe(false);
|
||||
expect(validateCrontab('61 24 * * *')).toBe(false);
|
||||
});
|
||||
|
||||
it('explains valid crontab expressions', () => {
|
||||
expect(explainCrontab('35 16 * * 0-5')).toMatch(/At 04:35 PM/);
|
||||
expect(explainCrontab('* * * * *')).toMatch(/Every minute/);
|
||||
});
|
||||
|
||||
it('returns error for invalid crontab explanation', () => {
|
||||
expect(explainCrontab('invalid expression')).toMatch(
|
||||
/Invalid crontab expression/
|
||||
);
|
||||
});
|
||||
});
|
128
src/pages/tools/time/crontab-guru/index.tsx
Normal file
128
src/pages/tools/time/crontab-guru/index.tsx
Normal file
@@ -0,0 +1,128 @@
|
||||
import { Alert } from '@mui/material';
|
||||
import React, { useState } from 'react';
|
||||
import ToolContent from '@components/ToolContent';
|
||||
import { ToolComponentProps } from '@tools/defineTool';
|
||||
import ToolTextInput from '@components/input/ToolTextInput';
|
||||
import ToolTextResult from '@components/result/ToolTextResult';
|
||||
import { CardExampleType } from '@components/examples/ToolExamples';
|
||||
import { main, validateCrontab } from './service';
|
||||
|
||||
const initialValues = {};
|
||||
|
||||
type InitialValuesType = typeof initialValues;
|
||||
|
||||
const exampleCards: CardExampleType<InitialValuesType>[] = [
|
||||
{
|
||||
title: 'Every day at 16:35, Sunday to Friday',
|
||||
description: 'At 16:35 on every day-of-week from Sunday through Friday.',
|
||||
sampleText: '35 16 * * 0-5',
|
||||
sampleResult: 'At 04:35 PM, Sunday through Friday',
|
||||
sampleOptions: {}
|
||||
},
|
||||
{
|
||||
title: 'Every minute',
|
||||
description: 'Runs every minute.',
|
||||
sampleText: '* * * * *',
|
||||
sampleResult: 'Every minute',
|
||||
sampleOptions: {}
|
||||
},
|
||||
{
|
||||
title: 'Every 5 minutes',
|
||||
description: 'Runs every 5 minutes.',
|
||||
sampleText: '*/5 * * * *',
|
||||
sampleResult: 'Every 5 minutes',
|
||||
sampleOptions: {}
|
||||
},
|
||||
{
|
||||
title: 'At 12:00 PM on the 1st of every month',
|
||||
description: 'Runs at noon on the first day of each month.',
|
||||
sampleText: '0 12 1 * *',
|
||||
sampleResult: 'At 12:00 PM, on day 1 of the month',
|
||||
sampleOptions: {}
|
||||
}
|
||||
];
|
||||
|
||||
export default function CrontabGuru({
|
||||
title,
|
||||
longDescription
|
||||
}: ToolComponentProps) {
|
||||
const [input, setInput] = useState<string>('');
|
||||
const [result, setResult] = useState<string>('');
|
||||
const [isValid, setIsValid] = useState<boolean | null>(null);
|
||||
const [hasInteracted, setHasInteracted] = useState<boolean>(false);
|
||||
|
||||
const compute = (values: InitialValuesType, input: string) => {
|
||||
if (hasInteracted) {
|
||||
setIsValid(validateCrontab(input));
|
||||
}
|
||||
setResult(main(input, values));
|
||||
};
|
||||
|
||||
const handleInputChange = (val: string) => {
|
||||
if (!hasInteracted) setHasInteracted(true);
|
||||
setInput(val);
|
||||
};
|
||||
|
||||
return (
|
||||
<ToolContent
|
||||
title={title}
|
||||
input={input}
|
||||
inputComponent={
|
||||
<ToolTextInput
|
||||
value={input}
|
||||
onChange={handleInputChange}
|
||||
placeholder="e.g. 35 16 * * 0-5"
|
||||
/>
|
||||
}
|
||||
resultComponent={
|
||||
<div style={{ position: 'relative', minHeight: 80 }}>
|
||||
{hasInteracted && isValid === false && (
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
zIndex: 2,
|
||||
pointerEvents: 'auto',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
background: 'transparent'
|
||||
}}
|
||||
>
|
||||
<Alert
|
||||
severity="error"
|
||||
style={{
|
||||
width: '80%',
|
||||
opacity: 0.85,
|
||||
textAlign: 'center',
|
||||
pointerEvents: 'none'
|
||||
}}
|
||||
>
|
||||
Invalid crontab expression.
|
||||
</Alert>
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
style={{
|
||||
filter: hasInteracted && isValid === false ? 'blur(1px)' : 'none',
|
||||
transition: 'filter 0.2s'
|
||||
}}
|
||||
>
|
||||
<ToolTextResult
|
||||
value={hasInteracted && isValid === false ? '' : result}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
initialValues={initialValues}
|
||||
exampleCards={exampleCards}
|
||||
getGroups={null}
|
||||
setInput={setInput}
|
||||
compute={compute}
|
||||
toolInfo={{ title: `What is a ${title}?`, description: longDescription }}
|
||||
/>
|
||||
);
|
||||
}
|
24
src/pages/tools/time/crontab-guru/meta.ts
Normal file
24
src/pages/tools/time/crontab-guru/meta.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { defineTool } from '@tools/defineTool';
|
||||
import { lazy } from 'react';
|
||||
|
||||
export const tool = defineTool('time', {
|
||||
name: 'Crontab explainer',
|
||||
path: 'crontab-guru',
|
||||
icon: 'mdi:calendar-clock',
|
||||
description:
|
||||
'Parse, validate, and explain crontab expressions in plain English.',
|
||||
shortDescription: 'Crontab expression parser and explainer',
|
||||
keywords: [
|
||||
'crontab',
|
||||
'cron',
|
||||
'schedule',
|
||||
'guru',
|
||||
'time',
|
||||
'expression',
|
||||
'parser',
|
||||
'explain'
|
||||
],
|
||||
longDescription:
|
||||
'Enter a crontab expression (like "35 16 * * 0-5") to get a human-readable explanation and validation. Useful for understanding and debugging cron schedules. Inspired by crontab.guru.',
|
||||
component: lazy(() => import('./index'))
|
||||
});
|
22
src/pages/tools/time/crontab-guru/service.ts
Normal file
22
src/pages/tools/time/crontab-guru/service.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import cronstrue from 'cronstrue';
|
||||
import { isValidCron } from 'cron-validator';
|
||||
|
||||
export function explainCrontab(expr: string): string {
|
||||
try {
|
||||
return cronstrue.toString(expr);
|
||||
} catch (e: any) {
|
||||
return `Invalid crontab expression: ${e.message}`;
|
||||
}
|
||||
}
|
||||
|
||||
export function validateCrontab(expr: string): boolean {
|
||||
return isValidCron(expr, { seconds: false, allowBlankDay: true });
|
||||
}
|
||||
|
||||
export function main(input: string, _options: any): string {
|
||||
if (!input.trim()) return '';
|
||||
if (!validateCrontab(input)) {
|
||||
return 'Invalid crontab expression.';
|
||||
}
|
||||
return explainCrontab(input);
|
||||
}
|
@@ -1,3 +1,4 @@
|
||||
import { tool as timeCrontabGuru } from './crontab-guru/meta';
|
||||
import { tool as timeBetweenDates } from './time-between-dates/meta';
|
||||
import { tool as daysDoHours } from './convert-days-to-hours/meta';
|
||||
import { tool as hoursToDays } from './convert-hours-to-days/meta';
|
||||
@@ -11,5 +12,6 @@ export const timeTools = [
|
||||
convertSecondsToTime,
|
||||
convertTimetoSeconds,
|
||||
truncateClockTime,
|
||||
timeBetweenDates
|
||||
timeBetweenDates,
|
||||
timeCrontabGuru
|
||||
];
|
||||
|
Reference in New Issue
Block a user