Merge pull request #167 from AshAnand34/crontab-guru-tool

Crontab guru tool
This commit is contained in:
Ibrahima G. Coulibaly
2025-07-08 18:01:16 +01:00
committed by GitHub
9 changed files with 377 additions and 154 deletions

303
.idea/workspace.xml generated
View File

@@ -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 @@
&quot;state&quot;: &quot;OPEN&quot;
}
}</component>
<component name="GitHubPullRequestState"><![CDATA[{
"prStates": [
<component name="GitHubPullRequestState">{
&quot;prStates&quot;: [
{
"id": {
"id": "PR_kwDOMJIfts51PkS9",
"number": 22
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts51PkS9&quot;,
&quot;number&quot;: 22
},
"lastSeen": 1741207144695
&quot;lastSeen&quot;: 1741207144695
},
{
"id": {
"id": "PR_kwDOMJIfts6NiNYl",
"number": 32
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6NiNYl&quot;,
&quot;number&quot;: 32
},
"lastSeen": 1741209723869
&quot;lastSeen&quot;: 1741209723869
},
{
"id": {
"id": "PR_kwDOMJIfts6Nheyd",
"number": 31
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6Nheyd&quot;,
&quot;number&quot;: 31
},
"lastSeen": 1741213371410
&quot;lastSeen&quot;: 1741213371410
},
{
"id": {
"id": "PR_kwDOMJIfts6NmRBs",
"number": 33
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6NmRBs&quot;,
&quot;number&quot;: 33
},
"lastSeen": 1741282429036
&quot;lastSeen&quot;: 1741282429036
},
{
"id": {
"id": "PR_kwDOMJIfts5zyFTs",
"number": 15
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts5zyFTs&quot;,
&quot;number&quot;: 15
},
"lastSeen": 1741535540953
&quot;lastSeen&quot;: 1741535540953
},
{
"id": {
"id": "PR_kwDOMJIfts6QQB3c",
"number": 59
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6QQB3c&quot;,
&quot;number&quot;: 59
},
"lastSeen": 1743018960900
&quot;lastSeen&quot;: 1743018960900
},
{
"id": {
"id": "PR_kwDOMJIfts6QMPEg",
"number": 58
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6QMPEg&quot;,
&quot;number&quot;: 58
},
"lastSeen": 1743019452983
&quot;lastSeen&quot;: 1743019452983
},
{
"id": {
"id": "PR_kwDOMJIfts6QZvRI",
"number": 61
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6QZvRI&quot;,
&quot;number&quot;: 61
},
"lastSeen": 1743103196866
&quot;lastSeen&quot;: 1743103196866
},
{
"id": {
"id": "PR_kwDOMJIfts6QqPrQ",
"number": 73
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6QqPrQ&quot;,
&quot;number&quot;: 73
},
"lastSeen": 1743265865001
&quot;lastSeen&quot;: 1743265865001
},
{
"id": {
"id": "PR_kwDOMJIfts6Qp5nI",
"number": 72
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6Qp5nI&quot;,
&quot;number&quot;: 72
},
"lastSeen": 1743338472110
&quot;lastSeen&quot;: 1743338472110
},
{
"id": {
"id": "PR_kwDOMJIfts6QsjlS",
"number": 76
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6QsjlS&quot;,
&quot;number&quot;: 76
},
"lastSeen": 1743352150953
&quot;lastSeen&quot;: 1743352150953
},
{
"id": {
"id": "PR_kwDOMJIfts6Q0JBe",
"number": 82
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6Q0JBe&quot;,
&quot;number&quot;: 82
},
"lastSeen": 1743470267269
&quot;lastSeen&quot;: 1743470267269
},
{
"id": {
"id": "PR_kwDOMJIfts6UE9-x",
"number": 102
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6UE9-x&quot;,
&quot;number&quot;: 102
},
"lastSeen": 1747171977348
&quot;lastSeen&quot;: 1747171977348
},
{
"id": {
"id": "PR_kwDOMJIfts6XPua_",
"number": 117
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6XPua_&quot;,
&quot;number&quot;: 117
},
"lastSeen": 1747929835864
&quot;lastSeen&quot;: 1747929835864
},
{
"id": {
"id": "PR_kwDOMJIfts6XY-mZ",
"number": 119
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6XY-mZ&quot;,
&quot;number&quot;: 119
},
"lastSeen": 1748028108508
&quot;lastSeen&quot;: 1748028108508
},
{
"id": {
"id": "PR_kwDOMJIfts6Xdz4n",
"number": 120
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6Xdz4n&quot;,
&quot;number&quot;: 120
},
"lastSeen": 1748282672214
&quot;lastSeen&quot;: 1748282672214
},
{
"id": {
"id": "PR_kwDOMJIfts6X_zxl",
"number": 131
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6X_zxl&quot;,
&quot;number&quot;: 131
},
"lastSeen": 1748881279494
&quot;lastSeen&quot;: 1748881279494
},
{
"id": {
"id": "PR_kwDOMJIfts6bhieT",
"number": 152
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6bhieT&quot;,
&quot;number&quot;: 152
},
"lastSeen": 1751848489082
&quot;lastSeen&quot;: 1751848489082
},
{
"id": {
"id": "PR_kwDOMJIfts6dOyRk",
"number": 154
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6dOyRk&quot;,
&quot;number&quot;: 154
},
"lastSeen": 1751849436454
&quot;lastSeen&quot;: 1751849436454
},
{
"id": {
"id": "PR_kwDOMJIfts6cHjNi",
"number": 153
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6cHjNi&quot;,
&quot;number&quot;: 153
},
"lastSeen": 1751849501498
&quot;lastSeen&quot;: 1751849501498
},
{
"id": {
"id": "PR_kwDOMJIfts6Zs1FN",
"number": 145
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6Zs1FN&quot;,
&quot;number&quot;: 145
},
"lastSeen": 1751849770308
&quot;lastSeen&quot;: 1751849770308
},
{
"id": {
"id": "PR_kwDOMJIfts6bgKi9",
"number": 150
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6bgKi9&quot;,
&quot;number&quot;: 150
},
"lastSeen": 1751850367300
&quot;lastSeen&quot;: 1751850367300
},
{
"id": {
"id": "PR_kwDOMJIfts6dv21R",
"number": 162
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6dv21R&quot;,
&quot;number&quot;: 162
},
"lastSeen": 1751893739514
&quot;lastSeen&quot;: 1751893739514
},
{
"id": {
"id": "PR_kwDOMJIfts6dwQJi",
"number": 163
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts6dwQJi&quot;,
&quot;number&quot;: 163
},
"lastSeen": 1751893861615
&quot;lastSeen&quot;: 1751893861615
}
]
}]]></component>
}</component>
<component name="GithubPullRequestsUISettings">{
&quot;selectedUrlAndAccountId&quot;: {
&quot;url&quot;: &quot;https://github.com/iib0011/omni-tools.git&quot;,
@@ -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">{
&quot;keyToString&quot;: {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;,
&quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;Docker.Dockerfile build.executor&quot;: &quot;Run&quot;,
&quot;Docker.Dockerfile.executor&quot;: &quot;Run&quot;,
&quot;Playwright.Create transparent PNG.should make png color transparent.executor&quot;: &quot;Run&quot;,
&quot;Playwright.JoinText Component.executor&quot;: &quot;Run&quot;,
&quot;Playwright.JoinText Component.should merge text pieces with specified join character.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
&quot;Vitest.compute function (1).executor&quot;: &quot;Run&quot;,
&quot;Vitest.compute function.executor&quot;: &quot;Run&quot;,
&quot;Vitest.mergeText.executor&quot;: &quot;Run&quot;,
&quot;Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false.executor&quot;: &quot;Run&quot;,
&quot;Vitest.mergeText.should merge lines, preserve blank lines and trailing spaces when both deleteBlankLines and deleteTrailingSpaces are false.executor&quot;: &quot;Run&quot;,
&quot;Vitest.parsePageRanges.executor&quot;: &quot;Run&quot;,
&quot;Vitest.removeDuplicateLines function.executor&quot;: &quot;Run&quot;,
&quot;Vitest.removeDuplicateLines function.newlines option.executor&quot;: &quot;Run&quot;,
&quot;Vitest.removeDuplicateLines function.newlines option.should filter newlines when newlines is set to filter.executor&quot;: &quot;Run&quot;,
&quot;Vitest.replaceText function (regexp mode).should return the original text when passed an invalid regexp.executor&quot;: &quot;Run&quot;,
&quot;Vitest.replaceText function.executor&quot;: &quot;Run&quot;,
&quot;Vitest.timeBetweenDates.executor&quot;: &quot;Run&quot;,
&quot;git-widget-placeholder&quot;: &quot;#167 on fork/AshAnand34/crontab-guru-tool&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Users/Ibrahima/IdeaProjects/omni-tools/src/pages/tools/json&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;npm.build.executor&quot;: &quot;Run&quot;,
&quot;npm.dev.executor&quot;: &quot;Run&quot;,
&quot;npm.lint.executor&quot;: &quot;Run&quot;,
&quot;npm.prebuild.executor&quot;: &quot;Run&quot;,
&quot;npm.script:create:tool.executor&quot;: &quot;Run&quot;,
&quot;npm.test.executor&quot;: &quot;Run&quot;,
&quot;npm.test:e2e.executor&quot;: &quot;Run&quot;,
&quot;npm.test:e2e:run.executor&quot;: &quot;Run&quot;,
&quot;prettierjs.PrettierConfiguration.Package&quot;: &quot;C:\\Users\\Ibrahima\\IdeaProjects\\omni-tools\\node_modules\\prettier&quot;,
&quot;project.structure.last.edited&quot;: &quot;Problems&quot;,
&quot;project.structure.proportion&quot;: &quot;0.0&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.2&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;refactai_advanced_settings&quot;,
&quot;ts.external.directory.path&quot;: &quot;C:\\Users\\Ibrahima\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<component name="ReactDesignerToolWindowState">
<option name="myId2Visible">
<map>

17
package-lock.json generated
View File

@@ -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",

View File

@@ -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",

View File

@@ -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'

View File

@@ -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/
);
});
});

View 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 }}
/>
);
}

View 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'))
});

View 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);
}

View File

@@ -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
];