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)
| Property | Type | Default | Description |
|---|---|---|---|
morningEnds | ClockTime | '11:59' | When morning period ends (HH:MM) |
noonEnds | ClockTime | '12:59' | When noon period ends |
afternoonEnds | ClockTime | '17:59' | When afternoon period ends |
eveningEnds | ClockTime | '23:59' | When evening period ends |
midnightEnds | ClockTime | '02:59' | When midnight period ends |
currentTime | ClockTime | Current time | Override current time (HH:MM) |
appendToMsg | string | '' | Text to append to messages |
prependToMsg | string | '' | Text to prepend to messages |
morningMessage | string | 'Good Morning!' | Custom morning greeting |
noonMessage | string | 'Good Noon!' | Custom noon greeting |
afternoonMessage | string | 'Good Afternoon!' | Custom afternoon greeting |
eveningMessage | string | 'Good Evening!' | Custom evening greeting |
midnightMessage | string | 'Hello, Night Owl!' | Custom midnight greeting |
defaultMessage | string | 'Greetings!' | Fallback greeting |
Time Period Logic
- Midnight: Until
midnightEnds(default: 02:59) - Morning: Until
morningEnds(default: 11:59) - Noon: Until
noonEnds(default: 12:59) - Afternoon: Until
afternoonEnds(default: 17:59) - 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 forgetGreetinggreet: Shortened alias forgetGreeting
Notes
- Time Validation: Only accepts valid 24-hour format times (HH:MM), Invalid times fall back to current time
- Type Safety: Enforces correct time string formats at compile time
- Message Construction: Prepends/appends text exactly as provided
- 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:
- Flexible time period configuration
- Type-safe time string handling
- Multiple entry points through aliases
- Customizable greeting messages
Last updated: Fri, May 22, 2026 07:46:19AM (Coordinated Universal Time)
