ClockTime
Avoid JavaScript's Date Class
Never use JavaScript's native Date class in Psychic applications. For time-only values without timezone, use Dream's ClockTime. JavaScript's Date always includes date and timezone, causing confusion. Dream's classes provide precise control over what you're representing.
// ❌ DON'T DO THIS
const badTime = new Date('1970-01-01T14:30:45')
// ✅ DO THIS INSTEAD
import { ClockTime } from '@rvoh/dream'
const goodTime = ClockTime.fromObject({ hour: 14, minute: 30, second: 45 })
const formatted = goodTime.toLocaleString({ hour: '2-digit', minute: '2-digit' })
Overview
ClockTime represents a time of day without timezone information. It's useful for:
- Business hours (e.g., "Open 9:00 AM - 5:00 PM")
- Schedules and recurring events (e.g., "Meeting every day at 2:30 PM")
- Time comparisons independent of date or timezone
- Representing Postgres
TIME WITHOUT TIME ZONEfields
Key characteristics:
- No timezone information (all timezone data is stripped)
- Microsecond precision (6 decimal places)
- No date component
- Suitable for abstract "time of day" concepts
Postgres Mapping
Database time without time zone columns are automatically converted to ClockTime objects when Dream models are loaded from the database.
Import
import { ClockTime } from '@rvoh/dream'
Creating ClockTime Instances
Current Time
// Current time (timezone info stripped)
ClockTime.now()
From Components
// From object
ClockTime.fromObject({ hour: 14, minute: 30 })
ClockTime.fromObject({ hour: 14, minute: 30, second: 45 })
ClockTime.fromObject({
hour: 14,
minute: 30,
second: 45,
millisecond: 123,
microsecond: 456,
})
// With options
ClockTime.fromObject({ hour: 14, minute: 30 }, { locale: 'fr-FR' })
From Strings
All parsing methods strip timezone information from the input string, preserving only the time values.
// From ISO 8601 time string (timezone ignored)
ClockTime.fromISO('14:30:45')
ClockTime.fromISO('14:30:45.123456')
ClockTime.fromISO('14:30:45-05:00') // stores 14:30:45, ignores -05:00
ClockTime.fromISO('14:30:45.123456+02:00') // stores 14:30:45.123456, ignores +02:00
// From SQL time string (timezone ignored)
ClockTime.fromSQL('14:30:45')
ClockTime.fromSQL('14:30:45.123456')
ClockTime.fromSQL('14:30:45+05:30') // stores 14:30:45, ignores +05:30
// From custom format
ClockTime.fromFormat('14:30:45', 'HH:mm:ss')
ClockTime.fromFormat('2:30 PM', 'h:mm a')
ClockTime.fromFormat('02:30:45', 'hh:mm:ss')
From DateTime
import { DateTime } from '@rvoh/dream'
const dt = DateTime.now()
ClockTime.fromDateTime(dt) // extracts time portion, strips timezone
From JavaScript Date
ClockTime.fromJSDate(new Date()) // extracts time, strips timezone
Formatting and Output
All output methods omit timezone offset by default.