Reference documentation and code samples for the Cloud Optimization V1 API class Google::Cloud::Optimization::V1::TimeWindow.
Time windows constrain the time of an event, such as the arrival time at a
visit, or the start and end time of a vehicle.
Hard time window bounds, start_time and end_time, enforce the earliest
and latest time of the event, such that start_time <= event_time <=
end_time. The soft time window lower bound, soft_start_time, expresses a
preference for the event to happen at or after soft_start_time by incurring
a cost proportional to how long before soft_start_time the event occurs. The
soft time window upper bound, soft_end_time, expresses a preference for the
event to happen at or before soft_end_time by incurring a cost proportional
to how long after soft_end_time the event occurs. start_time, end_time,
soft_start_time and soft_end_time should be within the global time limits
(see
ShipmentModel.global_start_time
and
ShipmentModel.global_end_time)
and should respect:
0 <= start_time <= soft_start_time <= end_time and
0 <= start_time <= soft_end_time <= end_time.
Inherits
Object
Extended By
Google::Protobuf::MessageExts::ClassMethods
Includes
Google::Protobuf::MessageExts
Methods
#cost_per_hour_after_soft_end_time
defcost_per_hour_after_soft_end_time()->::Float
Returns
(::Float) — A cost per hour added to other costs in the model if the event occurs after
soft_end_time, computed as:
max(0, t.seconds - soft_end_time.seconds)
* cost_per_hour_after_soft_end_time / 3600,
t being the time of the event.
This cost must be positive, and the field can only be set if
soft_end_time has been set.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-09 UTC."],[],[],null,["# Cloud Optimization V1 API - Class Google::Cloud::Optimization::V1::TimeWindow (v0.12.0)\n\nVersion latestkeyboard_arrow_down\n\n- [0.12.0 (latest)](/ruby/docs/reference/google-cloud-optimization-v1/latest/Google-Cloud-Optimization-V1-TimeWindow)\n- [0.11.1](/ruby/docs/reference/google-cloud-optimization-v1/0.11.1/Google-Cloud-Optimization-V1-TimeWindow)\n- [0.10.0](/ruby/docs/reference/google-cloud-optimization-v1/0.10.0/Google-Cloud-Optimization-V1-TimeWindow)\n- [0.9.2](/ruby/docs/reference/google-cloud-optimization-v1/0.9.2/Google-Cloud-Optimization-V1-TimeWindow)\n- [0.8.2](/ruby/docs/reference/google-cloud-optimization-v1/0.8.2/Google-Cloud-Optimization-V1-TimeWindow)\n- [0.7.0](/ruby/docs/reference/google-cloud-optimization-v1/0.7.0/Google-Cloud-Optimization-V1-TimeWindow)\n- [0.6.0](/ruby/docs/reference/google-cloud-optimization-v1/0.6.0/Google-Cloud-Optimization-V1-TimeWindow)\n- [0.5.0](/ruby/docs/reference/google-cloud-optimization-v1/0.5.0/Google-Cloud-Optimization-V1-TimeWindow)\n- [0.4.1](/ruby/docs/reference/google-cloud-optimization-v1/0.4.1/Google-Cloud-Optimization-V1-TimeWindow)\n- [0.3.0](/ruby/docs/reference/google-cloud-optimization-v1/0.3.0/Google-Cloud-Optimization-V1-TimeWindow)\n- [0.2.1](/ruby/docs/reference/google-cloud-optimization-v1/0.2.1/Google-Cloud-Optimization-V1-TimeWindow)\n- [0.1.1](/ruby/docs/reference/google-cloud-optimization-v1/0.1.1/Google-Cloud-Optimization-V1-TimeWindow) \nReference documentation and code samples for the Cloud Optimization V1 API class Google::Cloud::Optimization::V1::TimeWindow.\n\nTime windows constrain the time of an event, such as the arrival time at a\nvisit, or the start and end time of a vehicle.\n\n\n\u003cbr /\u003e\n\nHard time window bounds, `start_time` and `end_time`, enforce the earliest\nand latest time of the event, such that `start_time \u003c= event_time \u003c=\nend_time`. The soft time window lower bound, `soft_start_time`, expresses a\npreference for the event to happen at or after `soft_start_time` by incurring\na cost proportional to how long before soft_start_time the event occurs. The\nsoft time window upper bound, `soft_end_time`, expresses a preference for the\nevent to happen at or before `soft_end_time` by incurring a cost proportional\nto how long after `soft_end_time` the event occurs. `start_time`, `end_time`,\n`soft_start_time` and `soft_end_time` should be within the global time limits\n(see\n[ShipmentModel.global_start_time](/ruby/docs/reference/google-cloud-optimization-v1/latest/Google-Cloud-Optimization-V1-ShipmentModel#Google__Cloud__Optimization__V1__ShipmentModel_global_start_time_instance_ \"Google::Cloud::Optimization::V1::ShipmentModel#global_start_time (method)\")\nand\n[ShipmentModel.global_end_time](/ruby/docs/reference/google-cloud-optimization-v1/latest/Google-Cloud-Optimization-V1-ShipmentModel#Google__Cloud__Optimization__V1__ShipmentModel_global_end_time_instance_ \"Google::Cloud::Optimization::V1::ShipmentModel#global_end_time (method)\"))\nand should respect:\n`\n0 \u003c= ``start_time`` \u003c= ``soft_start_time`` \u003c= ``end_time`` and\n0 \u003c= ``start_time`` \u003c= ``soft_end_time`` \u003c= ``end_time``.\n` \n\nInherits\n--------\n\n- Object \n\nExtended By\n-----------\n\n- Google::Protobuf::MessageExts::ClassMethods \n\nIncludes\n--------\n\n- Google::Protobuf::MessageExts\n\nMethods\n-------\n\n### #cost_per_hour_after_soft_end_time\n\n def cost_per_hour_after_soft_end_time() -\u003e ::Float\n\n**Returns**\n\n- (::Float) --- A cost per hour added to other costs in the model if the event occurs after `soft_end_time`, computed as:\n\n\n `\n max(0, t.seconds - soft_end_time.seconds)\n * cost_per_hour_after_soft_end_time / 3600,\n t being the time of the event.\n `\n\n This cost must be positive, and the field can only be set if\n `soft_end_time` has been set.\n\n### #cost_per_hour_after_soft_end_time=\n\n def cost_per_hour_after_soft_end_time=(value) -\u003e ::Float\n\n**Parameter**\n\n- **value** (::Float) --- A cost per hour added to other costs in the model if the event occurs after `soft_end_time`, computed as:\n\n\n `\n max(0, t.seconds - soft_end_time.seconds)\n * cost_per_hour_after_soft_end_time / 3600,\n t being the time of the event.\n `\n\n This cost must be positive, and the field can only be set if\n`soft_end_time` has been set. \n**Returns**\n\n- (::Float) --- A cost per hour added to other costs in the model if the event occurs after `soft_end_time`, computed as:\n\n\n `\n max(0, t.seconds - soft_end_time.seconds)\n * cost_per_hour_after_soft_end_time / 3600,\n t being the time of the event.\n `\n\n This cost must be positive, and the field can only be set if\n `soft_end_time` has been set.\n\n### #cost_per_hour_before_soft_start_time\n\n def cost_per_hour_before_soft_start_time() -\u003e ::Float\n\n**Returns**\n\n- (::Float) --- A cost per hour added to other costs in the model if the event occurs before soft_start_time, computed as:\n\n `\n max(0, soft_start_time - t.seconds)\n * cost_per_hour_before_soft_start_time / 3600,\n t being the time of the event.\n `\n\n This cost must be positive, and the field can only be set if\n soft_start_time has been set.\n\n### #cost_per_hour_before_soft_start_time=\n\n def cost_per_hour_before_soft_start_time=(value) -\u003e ::Float\n\n**Parameter**\n\n- **value** (::Float) --- A cost per hour added to other costs in the model if the event occurs before soft_start_time, computed as:\n\n\n `\n max(0, soft_start_time - t.seconds)\n * cost_per_hour_before_soft_start_time / 3600,\n t being the time of the event.\n `\n\n This cost must be positive, and the field can only be set if\nsoft_start_time has been set. \n**Returns**\n\n- (::Float) --- A cost per hour added to other costs in the model if the event occurs before soft_start_time, computed as:\n\n `\n max(0, soft_start_time - t.seconds)\n * cost_per_hour_before_soft_start_time / 3600,\n t being the time of the event.\n `\n\n This cost must be positive, and the field can only be set if\n soft_start_time has been set.\n\n### #end_time\n\n def end_time() -\u003e ::Google::Protobuf::Timestamp\n\n**Returns**\n\n- ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- The hard time window end time. If unspecified it will be set to `ShipmentModel.global_end_time`.\n\n### #end_time=\n\n def end_time=(value) -\u003e ::Google::Protobuf::Timestamp\n\n**Parameter**\n\n- **value** ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- The hard time window end time. If unspecified it will be set to `ShipmentModel.global_end_time`. \n**Returns**\n\n- ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- The hard time window end time. If unspecified it will be set to `ShipmentModel.global_end_time`.\n\n### #soft_end_time\n\n def soft_end_time() -\u003e ::Google::Protobuf::Timestamp\n\n**Returns**\n\n- ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- The soft end time of the time window.\n\n### #soft_end_time=\n\n def soft_end_time=(value) -\u003e ::Google::Protobuf::Timestamp\n\n**Parameter**\n\n- **value** ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- The soft end time of the time window. \n**Returns**\n\n- ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- The soft end time of the time window.\n\n### #soft_start_time\n\n def soft_start_time() -\u003e ::Google::Protobuf::Timestamp\n\n**Returns**\n\n- ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- The soft start time of the time window.\n\n### #soft_start_time=\n\n def soft_start_time=(value) -\u003e ::Google::Protobuf::Timestamp\n\n**Parameter**\n\n- **value** ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- The soft start time of the time window. \n**Returns**\n\n- ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- The soft start time of the time window.\n\n### #start_time\n\n def start_time() -\u003e ::Google::Protobuf::Timestamp\n\n**Returns**\n\n- ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- The hard time window start time. If unspecified it will be set to `ShipmentModel.global_start_time`.\n\n### #start_time=\n\n def start_time=(value) -\u003e ::Google::Protobuf::Timestamp\n\n**Parameter**\n\n- **value** ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- The hard time window start time. If unspecified it will be set to `ShipmentModel.global_start_time`. \n**Returns**\n\n- ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- The hard time window start time. If unspecified it will be set to `ShipmentModel.global_start_time`."]]