Report post

Are you sure you want to report the post shown below? This will send an email to the ATVO administrators. Please include a short reason for reporting.

Users reporting for no reason may be locked out.


Post

Posted by Nick Thissen
on
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";
}
}
}
}