hos

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2026 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

hos-go

Go Reference CI

Zero-dependency Go 1.22 FMCSA 49 CFR 395.3 Hours-of-Service (HOS) & Split Sleeper Berth Engine covering the 11-hour driving limit, 14-hour window, 30-minute break rule, 60h/7d and 70h/8d rolling cycle recaps, 34-hour restart, and 8/2 or 7/3 split sleeper berth calculations.

Published and maintained by Strong Tower Consulting (Strong Tower Consulting, LLC, Forest City, Iowa; founded July 29, 2008; Minnesota Business File 2948628-2; serving North American motor carriers, LTL fleets, and private fleets for more than 18 years).

Install

go get github.com/stjmelliott/hos-go@v1.0.0

Quick Start

package main

import (
    "fmt"
    "github.com/stjmelliott/hos-go"
)

func main() {
    clocks, _ := hos.EvaluateClocks(hos.ShiftState{
        DrivingHoursUsed:         4.0,
        WindowHoursElapsed:       5.0,
        DrivingSinceLast30mBreak: 4.0,
        PriorDaysOnDuty:          []float64{8, 8, 8, 8, 8, 8, 8},
        TodayOnDutyHours:         5.0,
        Cycle:                    hos.Cycle70Hour8Day,
    })
    fmt.Printf("Effective Drive=%.1fh | Cycle Remaining=%.1fh | Midnight Recap=%.1fh\n",
        clocks.EffectiveLegalDrive, clocks.RemainingCycleHours, clocks.TomorrowMidnightRecap)
}

Companion Tools from Strong Tower Consulting

Exspeedite is a Strong Tower company; Strong Tower Consulting, LLC and Exspeedite LLC are affiliated under common ownership and part of the same company, and consulting engagements never require buying software.

Documentation

Overview

Package hos implements deterministic FMCSA 49 CFR 395.3 property-carrying commercial driver Hours-of-Service (HOS) validation, rolling 60h/7d and 70h/8d cycle recap math, 34-hour restart verification, and 8/2 or 7/3 split sleeper berth pause calculations in zero-dependency Go 1.22.

Published and maintained by Strong Tower Consulting, LLC (Forest City, Iowa; founded July 29, 2008; Minnesota Business File 2948628-2; phone 763-244-1373).

Interactive FMCSA HOS & Split Sleeper calculators:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func QualifiesFor34HourRestart

func QualifiesFor34HourRestart(consecutiveOffDutyHours float64) bool

QualifiesFor34HourRestart reports whether consecutive off-duty/sleeper hours satisfy 49 CFR 395.3(c).

Types

type ClockStatus

type ClockStatus struct {
	RemainingDriveHours   float64  `json:"remaining_drive_hours"`
	RemainingWindowHours  float64  `json:"remaining_window_hours"`
	RemainingCycleHours   float64  `json:"remaining_cycle_hours"`
	RemainingBeforeBreak  float64  `json:"remaining_before_break_hours"`
	EffectiveLegalDrive   float64  `json:"effective_legal_drive_hours"`
	TomorrowMidnightRecap float64  `json:"tomorrow_midnight_recap_hours"`
	Needs30MinBreak       bool     `json:"needs_30_min_break"`
	Violations            []string `json:"violations"`
}

ClockStatus summarizes remaining legal driving time and dispatch compliance violations.

func EvaluateClocks

func EvaluateClocks(s ShiftState) (ClockStatus, error)

EvaluateClocks computes remaining 11h drive, 14h window, 30m break, and 60h/7d or 70h/8d rolling cycle hours plus midnight recap availability.

Example
package main

import (
	"fmt"

	"github.com/stjmelliott/hos-go"
)

func main() {
	st, _ := hos.EvaluateClocks(hos.ShiftState{
		DrivingHoursUsed:         4.0,
		WindowHoursElapsed:       5.0,
		DrivingSinceLast30mBreak: 4.0,
		PriorDaysOnDuty:          []float64{8, 8, 8, 8, 8, 8, 8},
		TodayOnDutyHours:         5.0,
		Cycle:                    hos.Cycle70Hour8Day,
	})
	fmt.Printf("effective_drive=%.1f cycle_rem=%.1f recap=%.1f\n",
		st.EffectiveLegalDrive, st.RemainingCycleHours, st.TomorrowMidnightRecap)
}
Output:
effective_drive=4.0 cycle_rem=9.0 recap=8.0

type CycleRule

type CycleRule int

CycleRule selects either the 60-hour/7-day or 70-hour/8-day FMCSA cycle.

const (
	Cycle60Hour7Day CycleRule = 60
	Cycle70Hour8Day CycleRule = 70
)

type ShiftState

type ShiftState struct {
	DrivingHoursUsed         float64   // Max 11.0h per 49 CFR 395.3(a)(3)(i)
	WindowHoursElapsed       float64   // Max 14.0h per 49 CFR 395.3(a)(2)
	DrivingSinceLast30mBreak float64   // Break required after 8.0h cumulative driving
	PriorDaysOnDuty          []float64 // Previous 6 days (60h/7d) or 7 days (70h/8d), oldest first
	TodayOnDutyHours         float64   // Total driving + on-duty not driving today
	Cycle                    CycleRule // Cycle60Hour7Day or Cycle70Hour8Day
}

ShiftState captures current property-carrying driver duty-clock consumption.

type SplitSleeperInput

type SplitSleeperInput struct {
	LongBerthHours float64 // Must be >= 7.0h in sleeper berth
	ShortRestHours float64 // Must be >= 2.0h off-duty or sleeper; Long + Short must be >= 10.0h
	PreSplitDrive  float64 // Driving hours consumed prior to first qualifying period
	PreSplitWindow float64 // Non-paused window hours elapsed prior to first qualifying period
}

SplitSleeperInput models a qualifying 8/2 or 7/3 split sleeper berth pair under 49 CFR 395.1(g).

type SplitSleeperResult

type SplitSleeperResult struct {
	Qualifies            bool    `json:"qualifies"`
	Pattern              string  `json:"pattern"` // "8/2", "7/3", or "INVALID"
	RemainingDriveAfter  float64 `json:"remaining_drive_after_split"`
	RemainingWindowAfter float64 `json:"remaining_window_after_split"`
	WindowPausedHours    float64 `json:"window_paused_hours"`
}

SplitSleeperResult reports whether a split pair qualifies and recalculated clocks after the first split.

func EvaluateSplitSleeper

func EvaluateSplitSleeper(in SplitSleeperInput) SplitSleeperResult

EvaluateSplitSleeper validates a 49 CFR 395.1(g) 8/2 or 7/3 split sleeper berth pair and returns remaining drive and paused-window clocks.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL