Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

1.2 KB
Raw Blame
import { localIsoDate } from './localDate'

export type JourneyLifecycle = 'archived' | 'live' | 'upcoming' | 'completed' | 'draft'

export type JourneyStatusOverride = 'draft' | 'live' | 'completed'

export function computeJourneyLifecycle(
  status: string,
  tripDateMin: string | null | undefined,
  tripDateMax: string | null | undefined,
  /** The owner's own pick (#762); wins over the dates, never over archived. */
  override?: string | null,
): JourneyLifecycle {
  if (status === 'archived') return 'archived'
  if (override === 'draft' || override === 'live' || override === 'completed') return override

  if (tripDateMin && tripDateMax) {
    const today = localIsoDate()
    if (tripDateMin <= today && today <= tripDateMax) return 'live'
    if (tripDateMin > today) return 'upcoming'
    return 'completed'
  }

  if (!tripDateMin && !tripDateMax) {
    return 'draft'
  }

  // Single boundary: only start or only end
  if (tripDateMin && !tripDateMax) {
    const today = localIsoDate()
    return tripDateMin > today ? 'upcoming' : 'live'
  }
  if (!tripDateMin && tripDateMax) {
    const today = localIsoDate()
    return tripDateMax < today ? 'completed' : 'live'
  }

  return 'completed'
}