Time of day bindings

Posts: 785
Starting with version 1.20, several new data bindings will become available that deal with the live session time of day. Data includes the start date/time of the session, as well as the live date/time currently. Note that the live time of day will not "rewind" when you rewind the session to watch a replay.

The date and time of day reflect the in-game session time of day, shown as "Sim Time" in the sim.


The data is available in two ways:
  • As a pre-formatted string.
  • As a DateTime object (.NET) which you can use in scripts, or format yourself using the Text property.


Data bindings
Look for these data bindings in the sessionstate data set:

  • date: shows the current date in the session, pre-formatted in format "year-month-day" (for example: "2019-05-15"). The date will correctly update to the next day if the session passes midnight.
  • timeofday: shows the current time of day in the session, in pre-formatted "hours:minutes:seconds" format (for example: 14:04:32).
  • startdate: shows the start date of the session in pre-formatted format, but will not update to reflect the current day.
  • starttimeofday: shows the time of day in which the session started, in pre-formatted format, but will not update to reflect the current time.
  • livedatetime_object: returns a .NET DateTime object containing the current (live) date and time in the session. Requires scripting or manual formatting to use, see below.
  • startdatetime_object: returns a .NET DateTime object containing the starting date and time for the session. Requires scripting or manual formatting to use, see below.


Date and time formatting
If the pre-formatted date and time strings do not match your preference, you can use your own formatting in two ways.

Formatting via the Text property
If you bind to the "livedatetime_object" or "startdatetime_object" bindings, you can then use the Text property to apply your own custom date and time formatting. The format is applied via the usual {0:'format'} macro where 'format' is your custom date/time format string.

For example, if the date/time you are formatting is Monday November 18th, 2019, at 17:08:35:
  • {0:dddd d MMM yyyy} - returns "Monday 18 Nov 2019"
  • {0:h\:mm tt} - returns "5:08 pm"
  • {0:hh\:mm tt} - returns "05:08 pm"
  • {0:HH\:mm} - returns "17:08"
Note the use of the "\:" to escape the colon character so it is not interpreted as a formatting but will appear directly in the output.

Date/time formatting is extensively described in the .NET documentation, see especially the table of possible formats and examples:
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings


Scripting
Alternatively, you can use any converter script to cast the value to a DateTime object and apply your own formatting in any way you want:
using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;

namespace Scripts
{
public class TimeOfDayConverter : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// Bind to "livedatetime_object" and cast to DateTime:
var now = (DateTime)value;

// Suppose you figured out sunset is at 21:14:18 today:
var sunset = new TimeSpan(21,14,18);

// Calculate time until sunset
var timeUntilSunset = sunset - now.TimeOfDay;

if (timeUntilSunset.TotalSeconds > 0)
{
return timeUntilSunset.ToString("HH:mm:ss");
}
else
{
return "Sunset in progress";
}
}
}
}
Hello Nick,

Since the latest release (Release: version beta 1.20.1.0), 'Time of Day' data bindings aren't available anymore (sessionstate).
It works well before... Now I have {0:0}, {1} instead....

Can you check on your side?

Thx!
JC
Posts: 11
for some reason, I can't get time to match anymore in the sim it is alway 10mins behind.
Posts: 1
Is there anyway to apply an offset to the in game time of day?
Posts: 5
Robert A Moyer Jr wrote:
for some reason, I can't get time to match anymore in the sim it is alway 10mins behind.
This! ^
Posts: 5
Jayden Thurlow wrote:
Is there anyway to apply an offset to the in game time of day?
I'll let Nick chime in here but i would think a script would be able to do this when used as a data converter on the labels themselves.
Posts: 27
Robert A Moyer Jr wrote:
for some reason, I can't get time to match anymore in the sim it is alway 10mins behind.

I have found that the time of day always shows the time the session has gone for, then restarts to the original time of the session start even when the session ticks over to a new phase.

So for example - Session opens at 10am in sim time for 10 mins practice, stays accurate.

Then qualifying commences - Sim time is 10:10, but ATVO resets back to 10am

Then when the race session commences, the sim time resets back to 10am again.

Also counts time even if the session time of day remains static (0x)
Posts: 785
I will look into this, perhaps a bug was introduced some time ago. This should have been working including the time acceleration...
date time time of day timeofday