1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-19 11:39:36 +02:00

Adds support for 12hr time format

This commit is contained in:
Yusef Ouda 2024-07-03 15:16:17 -05:00
parent 3c347c854c
commit 5d679ea387
10 changed files with 41 additions and 4 deletions

View file

@ -29,6 +29,7 @@ export const getDateTime = (): string => {
const now = new Date(); const now = new Date();
const useAmericanDate = localStorage.useAmericanDate === 'true'; const useAmericanDate = localStorage.useAmericanDate === 'true';
const useAmericanTime = localStorage.useAmericanTime === 'true';
const showTime = localStorage.showTime === 'true'; const showTime = localStorage.showTime === 'true';
const hideDate = localStorage.hideDate === 'true'; const hideDate = localStorage.hideDate === 'true';
@ -50,11 +51,18 @@ export const getDateTime = (): string => {
// Time // Time
const p = parseTime; const p = parseTime;
let timeEl = ''; let timeEl = '';
let timePeriod = '';
if (showTime) { if (showTime) {
const time = `${p(now.getHours())}:${p(now.getMinutes())}:${p( let hours = now.getHours();
if (useAmericanTime) {
timePeriod = hours >= 12 ? ' PM' : ' AM';
hours = hours % 12 || 12;
}
const time = `${p(hours)}:${p(now.getMinutes())}:${p(
now.getSeconds() now.getSeconds()
)}`; )}${timePeriod}`;
timeEl = time; timeEl = time;
} }

View file

@ -99,7 +99,7 @@ export const AuthForm = (): JSX.Element => {
) : ( ) : (
<div> <div>
<p className={classes.text}> <p className={classes.text}>
You are logged in. Your session will expire{' '} You are logged in. Your session will expire on{' '}
<span>{tokenExpires}</span> <span>{tokenExpires}</span>
</p> </p>
<Button click={logout}>Logout</Button> <Button click={logout}>Logout</Button>

View file

@ -162,6 +162,20 @@ export const UISettings = (): JSX.Element => {
</select> </select>
</InputGroup> </InputGroup>
{/* TIME FORMAT */}
<InputGroup>
<label htmlFor="useAmericanTime">Time formatting</label>
<select
id="useAmericanTime"
name="useAmericanTime"
value={formData.useAmericanTime ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={1}>01:30 PM</option>
<option value={0}>13:30</option>
</select>
</InputGroup>
{/* CUSTOM GREETINGS */} {/* CUSTOM GREETINGS */}
<InputGroup> <InputGroup>
<label htmlFor="greetingsSchema">Custom greetings</label> <label htmlFor="greetingsSchema">Custom greetings</label>

View file

@ -23,6 +23,7 @@ export interface Config {
kubernetesApps: boolean; kubernetesApps: boolean;
unpinStoppedApps: boolean; unpinStoppedApps: boolean;
useAmericanDate: boolean; useAmericanDate: boolean;
useAmericanTime: boolean;
disableAutofocus: boolean; disableAutofocus: boolean;
greetingsSchema: string; greetingsSchema: string;
daySchema: string; daySchema: string;

View file

@ -25,6 +25,7 @@ export interface UISettingsForm {
hideApps: boolean; hideApps: boolean;
hideCategories: boolean; hideCategories: boolean;
useAmericanDate: boolean; useAmericanDate: boolean;
useAmericanTime: boolean;
greetingsSchema: string; greetingsSchema: string;
daySchema: string; daySchema: string;
monthSchema: string; monthSchema: string;

View file

@ -15,6 +15,7 @@ import { ConfigFormData } from '../../types';
const keys: (keyof Config)[] = [ const keys: (keyof Config)[] = [
'useAmericanDate', 'useAmericanDate',
'useAmericanTime',
'greetingsSchema', 'greetingsSchema',
'daySchema', 'daySchema',
'monthSchema', 'monthSchema',

View file

@ -13,7 +13,16 @@ export const parseTokenExpire = (expiresIn: number): string => {
const p = parseTime; const p = parseTime;
const useAmericanDate = localStorage.useAmericanDate === 'true'; const useAmericanDate = localStorage.useAmericanDate === 'true';
const time = `${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`; const useAmericanTime = localStorage.useAmericanTime === 'true';
let hours = d.getHours();
let timePeriod = '';
if (useAmericanTime) {
timePeriod = hours >= 12 ? ' PM' : ' AM';
hours = hours % 12 || 12;
}
const time = `${p(hours)}:${p(d.getMinutes())}:${p(d.getSeconds())}${timePeriod}`;
if (useAmericanDate) { if (useAmericanDate) {
return `${d.getMonth() + 1}/${d.getDate()}/${d.getFullYear()} ${time}`; return `${d.getMonth() + 1}/${d.getDate()}/${d.getFullYear()} ${time}`;

View file

@ -23,6 +23,7 @@ export const configTemplate: Config = {
kubernetesApps: false, kubernetesApps: false,
unpinStoppedApps: false, unpinStoppedApps: false,
useAmericanDate: false, useAmericanDate: false,
useAmericanTime: false,
disableAutofocus: false, disableAutofocus: false,
greetingsSchema: 'Good evening!;Good afternoon!;Good morning!;Good night!', greetingsSchema: 'Good evening!;Good afternoon!;Good morning!;Good night!',
daySchema: 'Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday', daySchema: 'Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday',

View file

@ -12,6 +12,7 @@ export const uiSettingsTemplate: UISettingsForm = {
hideApps: false, hideApps: false,
hideCategories: false, hideCategories: false,
useAmericanDate: false, useAmericanDate: false,
useAmericanTime: false,
greetingsSchema: 'Good evening!;Good afternoon!;Good morning!;Good night!', greetingsSchema: 'Good evening!;Good afternoon!;Good morning!;Good night!',
daySchema: 'Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday', daySchema: 'Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday',
monthSchema: monthSchema:

View file

@ -21,6 +21,7 @@
"kubernetesApps": false, "kubernetesApps": false,
"unpinStoppedApps": false, "unpinStoppedApps": false,
"useAmericanDate": false, "useAmericanDate": false,
"useAmericanTime": false,
"disableAutofocus": false, "disableAutofocus": false,
"greetingsSchema": "Good evening!;Good afternoon!;Good morning!;Good night!", "greetingsSchema": "Good evening!;Good afternoon!;Good morning!;Good night!",
"daySchema": "Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday", "daySchema": "Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday",