Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 24-hour format option to use Time hook for clarity #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export default function App() {

| key | Type | Required | Description |
| --- | --- | --- | ---- |
| format | string | No | if set to `12-hour` time will be formatted with am/pm |
| format | string | No | By default, the format is `24-hour`. If set to `12-hour`, time will be formatted with am/pm |
| interval | number | No | value to change the interval of the time, by default it is set to 1000ms. Note: this value will not affect the thime, it will just define the frequency used to calculate the current time values. For example, if you have a use case where milliseconds are used, you need to use a smaller value for the interval, for example, 20ms or 100ms based on your needs. |

### Values
Expand Down
4 changes: 2 additions & 2 deletions src/useTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { SECOND_INTERVAL } from './constants';
import { FormattedTimeFromMillisecondsType } from './utils/Time';

export type useTimeSettingsType = {
format?: '12-hour',
format?: '24-hour' | '12-hour',
interval?: number;
};

export default function useTime({ format, interval: customInterval = SECOND_INTERVAL }: useTimeSettingsType = {}): FormattedTimeFromMillisecondsType {
export default function useTime({ format = '24-hour', interval: customInterval = SECOND_INTERVAL }: useTimeSettingsType = {}): FormattedTimeFromMillisecondsType {
const [milliseconds, setMilliseconds] = useState(Time.getMillisecondsFromTimeNow());

useInterval(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class Time {
return currentTimestamp - offset;
}

static getFormattedTimeFromMilliseconds(milliseconds: number, format?: '12-hour'): FormattedTimeFromMillisecondsType {
static getFormattedTimeFromMilliseconds(milliseconds: number, format?: '12-hour' | '24-hour'): FormattedTimeFromMillisecondsType {
const {
milliseconds: millisecVal,
seconds: secondsValue,
Expand Down