Toolbox-XToolbox-X

Get Time-Based Greeting

Get Time-Based Greeting — Chronos Documentation.

getGreeting

Returns a time-appropriate greeting message based on configurable time periods. Supports custom messages and time thresholds.

Function Signature

getGreeting(configs?: GreetingConfigs): string;

Parameters (GreetingConfigs)

PropertyTypeDefaultDescription
morningEndsClockTime'11:59'When morning period ends (HH:MM)
noonEndsClockTime'12:59'When noon period ends
afternoonEndsClockTime'17:59'When afternoon period ends
eveningEndsClockTime'23:59'When evening period ends
midnightEndsClockTime'02:59'When midnight period ends
currentTimeClockTimeCurrent timeOverride current time (HH:MM)
appendToMsgstring''Text to append to messages
prependToMsgstring''Text to prepend to messages
morningMessagestring'Good Morning!'Custom morning greeting
noonMessagestring'Good Noon!'Custom noon greeting
afternoonMessagestring'Good Afternoon!'Custom afternoon greeting
eveningMessagestring'Good Evening!'Custom evening greeting
midnightMessagestring'Hello, Night Owl!'Custom midnight greeting
defaultMessagestring'Greetings!'Fallback greeting

Time Period Logic

  1. Midnight: Until midnightEnds (default: 02:59)
  2. Morning: Until morningEnds (default: 11:59)
  3. Noon: Until noonEnds (default: 12:59)
  4. Afternoon: Until afternoonEnds (default: 17:59)
  5. Evening: Until eveningEnds (default: 23:59)

Example Usage

playground.ts

Type Definitions

Time Types

type ClockHour = '00'|'01'|'02'|'03'|...'23';

type ClockMinute = '00'|'01'|'02'|'03'...|'59';

type ClockTime = `${ClockHour}:${ClockMinute}`;

GreetingConfigs Interface

interface GreetingConfigs {
  morningEnds?: ClockTime;
  noonEnds?: ClockTime;
  afternoonEnds?: ClockTime;
  eveningEnds?: ClockTime;
  midnightEnds?: ClockTime;
  currentTime?: ClockTime;
  appendToMsg?: string;
  prependToMsg?: string;
  morningMessage?: string;
  noonMessage?: string;
  afternoonMessage?: string;
  eveningMessage?: string;
  midnightMessage?: string;
  defaultMessage?: string;
}

Aliases

  • generateGreeting: Alias for getGreeting
  • greet: Shortened alias for getGreeting

Notes

  1. Time Validation: Only accepts valid 24-hour format times (HH:MM), Invalid times fall back to current time
  2. Type Safety: Enforces correct time string formats at compile time
  3. Message Construction: Prepends/appends text exactly as provided
  4. Period Detection: Uses inclusive ranges (<= end time)

Use Cases

  • Dynamic welcome messages
  • Time-based UI theming
  • Personalized greetings
  • Localized time period detection

Conclusion

The getGreeting function and its aliases provide:

  1. Flexible time period configuration
  2. Type-safe time string handling
  3. Multiple entry points through aliases
  4. Customizable greeting messages

Last updated: Fri, May 22, 2026 07:46:19AM (Coordinated Universal Time)

On this page