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 .
if (dateTimeData == nullptr )
Use C4DAtom::SetParameter() to set the DateTimeData of your parameter.
The custom data type must be specified in the GeData constructor.
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 .
if (!singleid || cid.
IsPartOf (*singleid,
nullptr ))
{
return false ;
}
DateTime Structure
Represents a date and a time.
Inside DateTimeData , DataTime is only accessible via those functions:
DateTime timeSet(1912, 6, 23, 23, 59, 59);
if (dateTimeData == nullptr )
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);
if (dateTimeData == nullptr )
if (value == nullptr )
DateTime dateTime(1912, 6, 23, 23, 59, 59);
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() .
const Char * pszFormat =
"%H:%M:%S - %A - %d / %b / %G" ;
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.
DiagnosticOutput (
"The current time @ converted to a string @" , dateTimeToString, dateToString);
GetMonthName() Retrieves the name of a month in the current Cinema 4D interface language. 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").
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.
DiagnosticOutput (
"The date 25 December 2015 converted to a julian day is @" , julianDay);
julianDay -= 0.5;
julianDay += 0.5;
Current DateTime
Retrieves the current date and time.
GetDateTimeNow() Retrieves the current system date time and fill the parameter t with it.
GetDateTimeNowGM() Retrieves the current system date time in GMT and fill the parameter t with it.
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.
{
DiagnosticOutput (
"Local time @ to GMT result is @" , localTimeToString, gmtTimeToString);
}
else
{
}
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 .
const maxon::String days[7] = {
"Monday" _s,
"Tuesday" _s,
"Wednesday" _s,
"Thursday" _s,
"Friday" _s,
"Saturday" _s,
"Sunday" _s };
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)
maxon::Int32 year = 2042, month = 125, day = 412, hrs = 42, min = 25, sec = 123456;
DiagnosticOutput (
"Date before validate @ @ @ and after @ @ @" , 2042, 125, 412, year, month, day);
DiagnosticOutput (
"Time before validate @ @ @ and after @ @ @" , 42, 25, 123456, hrs, min, sec);
Compare
There are several operators that can be used to compare DateTime .
DateTime::operator== : return true if the first DateTime is the same as the second.
DateTime::operator != : return true if the first DateTime is not the same as the second.
DateTime::operator<= : return true if the first DateTime is before or equal to the second.
DateTime::operator< : return true if the first DateTime is before the second.
DateTime::operator >= : return true if the first DateTime is after or equal to the second.
DateTime::operator > : return true if the first DateTime is after the second.
CompareDateTime (const DateTime &a, const DateTime &b) compare two DateTime and return less than 0 if a < b, equal to 0 if a == b and greater than 0 if a > b.
const DateTime t1(1976, 04, 02, 18, 55, 22);
const DateTime t2(2019, 12, 25, 12, 55, 22);
if (result < 0)
else if (result == 0)
else
Further Reading
void SetDateTime(const DateTime &d, Bool bSetDate=true, Bool bSetTime=true)
BaseContainer GetCustomDataTypeDefault(Int32 type)
DAYOFWEEK GetDayOfWeek(Int32 lYear, Int32 lMonth, Int32 lDay)
Definition: lib_description.h:315
Int32 GetType(void) const
Definition: c4d_gedata.h:391
void SetInt32(Int32 id, Int32 l)
Definition: c4d_basecontainer.h:501
static void Free(DateTimeData *&pData)
void SetString(Int32 id, const maxon::String &s)
Definition: c4d_basecontainer.h:565
DateTime FromJulianDay(Float64 j)
void ValidateTime(Int32 &hour, Int32 &minute, Int32 &second)
Definition: string.h:1199
Bool IsPartOf(const DescID &cmp, Int32 *pos) const
void GetDateTimeNow(DateTime &t)
#define DATETIME_DATE_CONTROL
Bool true, if it is a calendar.
Definition: customgui_datetime.h:20
Bool true if the maximized GUI is shown by default.
Definition: lib_description.h:126
String GetMonthName(Int month)
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
Int32 CompareDateTime(const DateTime &a, const DateTime &b)
Float64 Float
Definition: apibase.h:197
void SetBool(Int32 id, Bool b)
Definition: c4d_basecontainer.h:494
Definition: customgui_datetime.h:152
Bool SetParameter(const DescID &id, const BaseContainer ¶m, const DescID &groupid)
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:168
String FormatTime(const char *pszFormat, const DateTime &t)
#define DATETIME_GUI
DateTime custom GUI ID.
Definition: customgui_datetime.h:11
void ValidateDate(Int32 &year, Int32 &month, Int32 &day)
#define DATETIME_TIME_CONTROL
Bool true, if it is a clock.
Definition: customgui_datetime.h:19
Represents a date and time.
Definition: customgui_datetime.h:34
int32_t Int32
32 bit signed integer datatype.
Definition: apibase.h:172
Float64 GetJulianDay(const DateTime &t)
String Short name, for attributes dialog.
Definition: lib_description.h:88
Represents a level within a DescID.
Definition: lib_description.h:274
Definition: c4d_gedata.h:77
Bool ParseTimeString(String timestr, Int32 &hour, Int32 &minute, Int32 &second)
String DateToString(const DateTime &d)
Dummy value for the default value GeData constructor.
Definition: c4d_gedata.h:60
Int32 The ID of the GUI for this element. Either a custom ID or one of: CUSTOMGUI
Definition: lib_description.h:121
DateTime GetDateTime() const
#define FormatString(...)
Definition: string.h:2035
TYPE * Release()
Definition: ge_autoptr.h:116
Definition: ge_autoptr.h:32
#define DATETIME_DATA
DateTime custom data ID.
Definition: customgui_datetime.h:14
CustomDataType * GetCustomDataType(Int32 datatype) const
Definition: c4d_gedata.h:485
#define DATETIME_NOW_BUTTON
Bool true, to add "Now" button.
Definition: customgui_datetime.h:21
String Name for standalone use.
Definition: lib_description.h:87
String TimeToString(const DateTime &d, const Bool bShowSeconds=true)
maxon::Bool Bool
Definition: ge_sys_math.h:40
Int32 month
Month.
Definition: customgui_datetime.h:58
maxon::Char Char
Definition: ge_sys_math.h:41
Bool LocalToGMTime(const DateTime &tLocal, DateTime &tGMT)
Definition: oskyshader.h:54
Definition: c4d_basecontainer.h:42