DateTimeData Manual

About

A DateTimeData stores a date and a time. Using a DateTime structure, it stores the year, month, day, hour, minute and second.
For more specific operation related to time, see TimeValue Manual.

Access

Use C4DAtom::GetParameter() to retrieve the data of a parameter and cast it to DateTimeData.

// This example retrieves the actual DateTime from a sky object.
GeData data;
// Retrieves the parameter from the physical sky object.
Bool success = mySkyObject->GetParameter(SKY_DATE_TIME, data, DESCFLAGS_GET::NONE);
// Checks if we retrieved the data and its type.
if (!success || data.GetType() != DATETIME_DATA)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// Retrieves the data from data container.
DateTimeData* dateTimeData = static_cast<DateTimeData*>(data.GetCustomDataType(DATETIME_DATA));
if (dateTimeData == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);

Use C4DAtom::SetParameter() to set the DateTimeData of your parameter.
The custom data type must be specified in the GeData constructor.

// Sets the physical sky object parameter with the new data.
Bool success = mySkyObject->SetParameter(DescID(SKY_DATE_TIME), GeData(DATETIME_DATA, dateTimeData), DESCFLAGS_SET::NONE);
if (!success)
return maxon::UnknownError(MAXON_SOURCE_LOCATION);

Add a parameter in a description

A parameter can be added to a description with the function ::GetDDescription(). To attach a custom GUI to that parameter define DESC_CUSTOMGUI settings and call SetParameter(). See DateTimeControl Manual.

// This example shows how to implement a BaseTimeData parameter with a custom GUI.
DescID cid = DescLevel(dateTimeID, DATETIME_DATA, 0);
if (!singleid || cid.IsPartOf(*singleid, nullptr))
{
// Sets the name
settings.SetString(DESC_NAME, "Date Time"_s);
settings.SetString(DESC_SHORT_NAME, "Date Time"_s);
// Sets the custom GUI displaying that parameter.
// GetCustomDataTypeDefault sets it to DATETIME_GUI by default.
// Activates the now button
settings.SetBool(DATETIME_NOW_BUTTON, true);
// Activates the clock
settings.SetBool(DATETIME_TIME_CONTROL, true);
// Activates the calendar
settings.SetBool(DATETIME_DATE_CONTROL, true);
// The maximized GUI is shown by default.
settings.SetBool(DESC_GUIOPEN, true);
// Inserts the parameter in the description
if (!description->SetParameter(cid, settings, ID_OBJECTPROPERTIES))
return false;
}

DateTime Structure

Represents a date and a time.

Inside DateTimeData, DataTime is only accessible via those functions:

// This example shows how to set and get a DateTimeData.
// Creates a DateTime for Alan Turing's birthday.
DateTime timeSet(1912, 6, 23, 23, 59, 59);
// Allocates a new DateTimeData.
if (dateTimeData == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
// Sets the DateTimeData to the new time/date.
dateTimeData->SetDateTime(timeSet);
// Retrieves the DateTime From DateTimeData.
const DateTime timeGet = dateTimeData->GetDateTime();

DateTime Properties

The Structure of the DateTime is composed by those properties.

Constructors

A DateTime can be created passing some argument in the constructor as follow:

DateTime (Int32 t_year, Int32 t_month, Int32 t_day, Int32 t_hour, Int32 t_minute, Int32 t_second);

// Allocates a new DateTimeData using AutoAlloc.
if (dateTimeData == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
// Released the pointer if needed.
DateTimeData* anotherPointer = dateTimeData.Release();
// Another way to Alloc a DateTimeData using GeData.
if (value == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
// Creates a Date time.
DateTime dateTime(1912, 6, 23, 23, 59, 59);
// Sets the DateTimeData.
value->SetDateTime(dateTime);
// Frees the pointer as we took ownership.
DateTimeData::Free(anotherPointer);

Functionality

There are several functions to manipulate dates and times.

String

DateTime can be converted as a String with:

  • FormatTime() Formats the given DateTime t and output it as a string. The format options are the same as strftime().
    // Retrieves a DateTime to a string format.
    // Displays a DateTime 22:32:44 Thursday - 23 / Aug / 2001.
    const Char* pszFormat = "%H:%M:%S - %A - %d / %b / %G";
    maxon::String dateTimeString = FormatTime(pszFormat, currentTime);
    DiagnosticOutput("The DateTime @ in string using @ format result is @", dateTimeToString, pszFormat, dateTimeString);
  • TimeToString() Converts a time as a formatted string (e.g. "12:34:56").
  • DateToString() Converts a date as a formatted string. The format of the returned string depends on the current OS date and time settings.
    // Converts a date as a formatted string.
    const maxon::String dateToString = DateToString(currentTime);
    // The output format depends on the os Date and time settings.
    DiagnosticOutput("The current time @ converted to a string @", dateTimeToString, dateToString);
  • GetMonthName() Retrieves the name of a month in the current Cinema 4D interface language.
    // This example gets the month's name from today's Date.
    // Sets a DateTime to now.
    DateTime now;
    // Retrieves the month's name in the current Cinema 4D interface language.
    const maxon::String month = GetMonthName(now.month);
    // Outputs the result.
    DiagnosticOutput("The actual monmth is @", month);
    DateTime can also be parsed from String to Int32 with thoses functions:
  • ParseTimeString() Parses a time string (e.g. "12:34:56").
  • ParseDateString() Parses a date string (e.g. "31/12/2010").
    // Parses a time string to Int32.
    maxon::Int32 hrs, min, sec;
    maxon::String time = "12:34:56"_s;
    // Checks the result of the function.
    if (!ParseTimeString(time, hrs, min, sec))
    return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
    DiagnosticOutput("This time @ can be parse to @ hours @ minutes @ seconds", time, hrs, min, sec);

Julian format

Transforms DateTime to Julian date in both directions.

  • GetJulianDay() return the modified Julian date. To get the correct Julian day, take the integer of the value and subtract 0.5.
  • FromJulianDay() return a DateTime from the modified Julian date.
    // This example use a Julian day.
    const DateTime dateTime = DateTime(2015, 12, 25, 12, 32, 59);
    maxon::Float julianDay = GetJulianDay(dateTime);
    // Outputs "2457382.523".
    DiagnosticOutput("The date 25 December 2015 converted to a julian day is @", julianDay);
    // Outputs "2457382.023".
    julianDay -= 0.5;
    DiagnosticOutput("To get the correct Julian day, subtract 0.5 @", julianDay);
    // We need to add 0.5 to a Julian day before using FromJulianDay.
    julianDay += 0.5;
    const DateTime backToTime = FromJulianDay(julianDay);
    // Outputs "12:32:59 - Friday - 25 / Dec / 2014".
    DiagnosticOutput("Date from julian day is @", FormatString(FormatTime(pszFormat, backToTime)));

Current DateTime

Retrieves the current date and time.

Convert DateTime

Converts date and time to GMT or local date and time.

  • LocalToGMTime() Converts local time to GMT depending on the OS time zone settings.
    Warning
    LocalToGMTime will fail if the local date is before Jan 1, 1970 2.01 am or after Jan 18, 2038 7 pm.
  • GMTimeToLocal() Converts GMT time to local depending on the OS time zone settings.
    // This example transform a DateTime to a LocalGMT time value.
    // Sets a DateTime to now.
    DateTime now;
    DateTime outGMT;
    if (LocalToGMTime(now, outGMT))
    {
    const maxon::String localTimeToString = FormatTime("%H:%M:%S - %A - %d / %b / %G", now);
    const maxon::String gmtTimeToString = FormatTime("%H:%M:%S - %A - %d / %b / %G", outGMT);
    DiagnosticOutput("Local time @ to GMT result is @", localTimeToString, gmtTimeToString);
    }
    else
    {
    DiagnosticOutput("Failed to convert the local time to a GMT");
    }

Day of week

Gets the day of the week.

  • GetDayOfWeek() Gets the day of the week of the date lYear-lMonth-lDay and return DAYOFWEEK.
    // Retrieves witch day of the week Alan Turing is born.
    // Create an array for all days of the week.
    const maxon::String days[7] = { "Monday"_s, "Tuesday"_s, "Wednesday"_s, "Thursday"_s, "Friday"_s, "Saturday"_s, "Sunday"_s };
    // GetDayOfWeek return a DAYOFWEEK so we need to cast that into a Int32 to retrieves the text in our days' array.
    const maxon::Int32 day = static_cast<maxon::Int32>(GetDayOfWeek(1912, 6, 23));
    // Outputs the result.
    DiagnosticOutput("Alan Turing is born a @", days[day]);

Validate

Tries to correct invalid data.

  • ValidateDate() Tries to correct invalid date values, e.g. clamping the values within valid limits. (1700-2299, 1-12, compatible day for the passed month)
  • ValidateTime() Tries to correct invalid time values, e.g. clamping the values within valid limits. (0h-23h 0-59m 0-59s)
    // Tries to correct the data of a DateTime.
    maxon::Int32 year = 2042, month = 125, day = 412, hrs = 42, min = 25, sec = 123456;
    ValidateDate(year, month, day);
    DiagnosticOutput("Date before validate @ @ @ and after @ @ @", 2042, 125, 412, year, month, day);
    ValidateTime(hrs, min, sec);
    DiagnosticOutput("Time before validate @ @ @ and after @ @ @", 42, 25, 123456, hrs, min, sec);

Compare

There are several operators that can be used to compare DateTime.

Further Reading

DateTimeData::SetDateTime
void SetDateTime(const DateTime &d, Bool bSetDate=true, Bool bSetTime=true)
GetCustomDataTypeDefault
BaseContainer GetCustomDataTypeDefault(Int32 type)
GetDayOfWeek
DAYOFWEEK GetDayOfWeek(Int32 lYear, Int32 lMonth, Int32 lDay)
DescID
Definition: lib_description.h:328
GeData::GetType
Int32 GetType(void) const
Definition: c4d_gedata.h:407
BaseContainer::SetInt32
void SetInt32(Int32 id, Int32 l)
Definition: c4d_basecontainer.h:505
DateTimeData::Free
static void Free(DateTimeData *&pData)
BaseContainer::SetString
void SetString(Int32 id, const maxon::String &s)
Definition: c4d_basecontainer.h:569
FromJulianDay
DateTime FromJulianDay(Float64 j)
ValidateTime
void ValidateTime(Int32 &hour, Int32 &minute, Int32 &second)
maxon::String
Definition: string.h:1213
DescID::IsPartOf
Bool IsPartOf(const DescID &cmp, Int32 *pos) const
GetDateTimeNow
void GetDateTimeNow(DateTime &t)
DATETIME_DATE_CONTROL
#define DATETIME_DATE_CONTROL
Bool true, if it is a calendar.
Definition: customgui_datetime.h:29
DESC_GUIOPEN
@ DESC_GUIOPEN
Bool true if the maximized GUI is shown by default.
Definition: lib_description.h:130
GetMonthName
String GetMonthName(Int month)
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
CompareDateTime
Int32 CompareDateTime(const DateTime &a, const DateTime &b)
maxon::Float
Float64 Float
Definition: apibase.h:195
BaseContainer::SetBool
void SetBool(Int32 id, Bool b)
Definition: c4d_basecontainer.h:498
DateTimeData
Definition: customgui_datetime.h:156
Description::SetParameter
Bool SetParameter(const DescID &id, const BaseContainer &param, const DescID &groupid)
DESCFLAGS_SET::NONE
@ NONE
None.
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:167
FormatTime
String FormatTime(const char *pszFormat, const DateTime &t)
DATETIME_GUI
#define DATETIME_GUI
DateTime custom GUI ID.
Definition: customgui_datetime.h:20
ValidateDate
void ValidateDate(Int32 &year, Int32 &month, Int32 &day)
DATETIME_TIME_CONTROL
#define DATETIME_TIME_CONTROL
Bool true, if it is a clock.
Definition: customgui_datetime.h:28
DateTime
Represents a date and time.
Definition: customgui_datetime.h:38
maxon::Int32
int32_t Int32
32 bit signed integer datatype.
Definition: apibase.h:174
GetJulianDay
Float64 GetJulianDay(const DateTime &t)
DESC_SHORT_NAME
@ DESC_SHORT_NAME
String Short name, for attributes dialog.
Definition: lib_description.h:92
DescLevel
Represents a level within a DescID.
Definition: lib_description.h:287
SKY_DATE_TIME
@ SKY_DATE_TIME
Definition: oskyshader.h:54
GeData
Definition: c4d_gedata.h:82
ParseTimeString
Bool ParseTimeString(String timestr, Int32 &hour, Int32 &minute, Int32 &second)
DateToString
String DateToString(const DateTime &d)
DEFAULTVALUE
@ DEFAULTVALUE
Dummy value for the default value GeData constructor.
Definition: c4d_gedata.h:65
DESC_CUSTOMGUI
@ DESC_CUSTOMGUI
Int32 The ID of the GUI for this element. Either a custom ID or one of: CUSTOMGUI
Definition: lib_description.h:125
DateTimeData::GetDateTime
DateTime GetDateTime() const
FormatString
#define FormatString(...)
Definition: string.h:2052
AutoAlloc::Release
TYPE * Release()
Definition: ge_autoptr.h:120
AutoAlloc
Definition: ge_autoptr.h:36
DESCFLAGS_GET::NONE
@ NONE
None.
DATETIME_DATA
#define DATETIME_DATA
DateTime custom data ID.
Definition: customgui_datetime.h:23
GeData::GetCustomDataType
CustomDataType * GetCustomDataType(Int32 datatype) const
Definition: c4d_gedata.h:507
DATETIME_NOW_BUTTON
#define DATETIME_NOW_BUTTON
Bool true, to add "Now" button.
Definition: customgui_datetime.h:30
DESC_NAME
@ DESC_NAME
String Name for standalone use.
Definition: lib_description.h:91
TimeToString
String TimeToString(const DateTime &d, const Bool bShowSeconds=true)
Bool
maxon::Bool Bool
Definition: ge_sys_math.h:55
DateTime::month
Int32 month
Month.
Definition: customgui_datetime.h:63
Char
maxon::Char Char
Definition: ge_sys_math.h:56
LocalToGMTime
Bool LocalToGMTime(const DateTime &tLocal, DateTime &tGMT)
BaseContainer
Definition: c4d_basecontainer.h:46
ID_OBJECTPROPERTIES
@ ID_OBJECTPROPERTIES
Definition: obase.h:56