mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-21 23:19:30 +02:00
82
src/pages/tools/time/check-leap-years/index.tsx
Normal file
82
src/pages/tools/time/check-leap-years/index.tsx
Normal file
@@ -0,0 +1,82 @@
|
||||
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 { GetGroupsType } from '@components/options/ToolOptions';
|
||||
import { CardExampleType } from '@components/examples/ToolExamples';
|
||||
import { checkLeapYear } from './service';
|
||||
|
||||
const initialValues = {};
|
||||
|
||||
type InitialValuesType = typeof initialValues;
|
||||
|
||||
const exampleCards: CardExampleType<InitialValuesType>[] = [
|
||||
{
|
||||
title: 'Find Birthdays on February 29',
|
||||
description:
|
||||
"One of our friends was born on a leap year on February 29th and as a consequence, she has a birthday only once every 4 years. As we can never really remember when her birthday is, we are using our program to create a reminder list of the upcoming leap years. To create a list of her next birthdays, we load a sequence of years from 2025 to 2040 into the input and get the status of each year. If the program says that it's a leap year, then we know that we'll be invited to a birthday party on February 29th.",
|
||||
sampleText: `2025
|
||||
2026
|
||||
2027
|
||||
2028
|
||||
2029
|
||||
2030
|
||||
2031
|
||||
2032
|
||||
2033
|
||||
2034
|
||||
2035
|
||||
2036
|
||||
2037
|
||||
2038
|
||||
2039
|
||||
2040`,
|
||||
sampleResult: `2025 is not a leap year.
|
||||
2026 is not a leap year.
|
||||
2027 is not a leap year.
|
||||
2028 is a leap year.
|
||||
2029 is not a leap year.
|
||||
2030 is not a leap year.
|
||||
2031 is not a leap year.
|
||||
2032 is a leap year.
|
||||
2033 is not a leap year.
|
||||
2034 is not a leap year.
|
||||
2035 is not a leap year.
|
||||
2036 is a leap year.
|
||||
2037 is not a leap year.
|
||||
2038 is not a leap year.
|
||||
2039 is not a leap year.
|
||||
2040 is a leap year.`,
|
||||
sampleOptions: {}
|
||||
}
|
||||
];
|
||||
|
||||
export default function ConvertDaysToHours({
|
||||
title,
|
||||
longDescription
|
||||
}: ToolComponentProps) {
|
||||
const [input, setInput] = useState<string>('');
|
||||
const [result, setResult] = useState<string>('');
|
||||
|
||||
const compute = (optionsValues: typeof initialValues, input: string) => {
|
||||
setResult(checkLeapYear(input));
|
||||
};
|
||||
|
||||
const getGroups: GetGroupsType<InitialValuesType> | null = () => [];
|
||||
|
||||
return (
|
||||
<ToolContent
|
||||
title={title}
|
||||
input={input}
|
||||
inputComponent={<ToolTextInput value={input} onChange={setInput} />}
|
||||
resultComponent={<ToolTextResult value={result} />}
|
||||
initialValues={initialValues}
|
||||
getGroups={getGroups}
|
||||
setInput={setInput}
|
||||
compute={compute}
|
||||
toolInfo={{ title: `What is a ${title}?`, description: longDescription }}
|
||||
exampleCards={exampleCards}
|
||||
/>
|
||||
);
|
||||
}
|
14
src/pages/tools/time/check-leap-years/meta.ts
Normal file
14
src/pages/tools/time/check-leap-years/meta.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { defineTool } from '@tools/defineTool';
|
||||
import { lazy } from 'react';
|
||||
|
||||
export const tool = defineTool('time', {
|
||||
path: 'check-leap-years',
|
||||
name: 'Check Leap Years',
|
||||
icon: 'arcticons:calendar-simple-29',
|
||||
description:
|
||||
' You can check if a given calendar year is a leap year. You can enter one or many different years into the input field with one date per line and get the answer to the test question of whether the given year is a leap year.',
|
||||
shortDescription: 'Convert days to hours easily.',
|
||||
keywords: ['check', 'leap', 'years'],
|
||||
longDescription: `This is a quick online utility for testing if the given year is a leap year. Just as a reminder, a leap year has 366 days, which is one more day than a common year. This extra day is added to the month of February and it falls on February 29th. There's a simple mathematical formula for calculating if the given year is a leap year. Leap years are those years that are divisible by 4 but not divisible by 100, as well as years that are divisible by 100 and 400 simultaneously. Our algorithm checks each input year using this formula and outputs the year's status. For example, if you enter the value "2025" as input, the program will display "2025 is not a leap year.", and for the value "2028", the status will be "2028 is a leap year.". You can also enter multiple years as the input in a column and get a matching column of statuses as the output.`,
|
||||
component: lazy(() => import('./index'))
|
||||
});
|
25
src/pages/tools/time/check-leap-years/service.ts
Normal file
25
src/pages/tools/time/check-leap-years/service.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
function isLeapYear(year: number): boolean {
|
||||
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
||||
}
|
||||
|
||||
export function checkLeapYear(input: string): string {
|
||||
if (!input) return '';
|
||||
|
||||
const years = input
|
||||
.split('\n')
|
||||
.map((year) => year.trim())
|
||||
.filter((year) => year !== '');
|
||||
|
||||
const results = years.map((yearStr) => {
|
||||
if (!/^\d{1,4}$/.test(yearStr)) {
|
||||
return `${yearStr}: Invalid year`;
|
||||
}
|
||||
|
||||
const year = Number(yearStr);
|
||||
return `${year} ${
|
||||
isLeapYear(year) ? 'is a leap year.' : 'is not a leap year.'
|
||||
}`;
|
||||
});
|
||||
|
||||
return results.join('\n');
|
||||
}
|
@@ -5,6 +5,7 @@ import { tool as hoursToDays } from './convert-hours-to-days/meta';
|
||||
import { tool as convertSecondsToTime } from './convert-seconds-to-time/meta';
|
||||
import { tool as convertTimetoSeconds } from './convert-time-to-seconds/meta';
|
||||
import { tool as truncateClockTime } from './truncate-clock-time/meta';
|
||||
import { tool as checkLeapYear } from './check-leap-years/meta';
|
||||
|
||||
export const timeTools = [
|
||||
daysDoHours,
|
||||
@@ -13,5 +14,6 @@ export const timeTools = [
|
||||
convertTimetoSeconds,
|
||||
truncateClockTime,
|
||||
timeBetweenDates,
|
||||
timeCrontabGuru
|
||||
timeCrontabGuru,
|
||||
checkLeapYear
|
||||
];
|
||||
|
Reference in New Issue
Block a user