github.com/256dpi/max-go@v0.7.0/lib/max/ext_systime.h (about) 1 2 #ifndef _EXT_SYSTIME_H_ 3 #define _EXT_SYSTIME_H_ 4 5 #include "ext_prefix.h" 6 #include "max_types.h" 7 8 BEGIN_USING_C_LINKAGE 9 10 #if C74_PRAGMA_STRUCT_PACKPUSH 11 #pragma pack(push, 2) 12 #elif C74_PRAGMA_STRUCT_PACK 13 #pragma pack(2) 14 #endif 15 16 17 /** 18 The Systime data structure. 19 @ingroup systime 20 */ 21 22 typedef struct _datetime { 23 t_uint32 year; ///< year 24 t_uint32 month; ///< month, in range 1 through 12 25 t_uint32 day; ///< day, in range 1 through 31 26 t_uint32 hour; ///< hour 27 t_uint32 minute; ///< minute 28 t_uint32 second; ///< second 29 t_uint32 millisecond; ///< (reserved for future use) 30 } t_datetime; 31 32 /** Flags for the sysdateformat_formatdatetime() function. 33 @ingroup systime 34 */ 35 typedef enum { 36 SYSDATEFORMAT_FLAGS_SHORT = 1, ///< short 37 SYSDATEFORMAT_FLAGS_MEDIUM = 2, ///< medium 38 SYSDATEFORMAT_FLAGS_LONG = 3, ///< long 39 40 SYSDATEFORMAT_RELATIVE = 16 41 } e_max_dateflags; 42 43 /** 44 Find out the operating system’s time in ticks. 45 @ingroup systime 46 @return the system time in ticks. 47 */ 48 t_uint32 systime_ticks(void); 49 50 51 /** 52 Find out the operating system’s time in milliseconds. 53 Note that this is approximately the number of milliseconds since the OS was started up. 54 @ingroup systime 55 @return the system time in milliseconds. 56 */ 57 t_uint32 systime_ms(void); 58 59 60 /** 61 Find out the current date/time as number of ms since January 1, 1970, GMT. 62 @ingroup systime 63 @return the number of milliseconds since January 1, 1970, GMT. 64 */ 65 t_int64 systime_datetime_milliseconds(void); 66 67 /** 68 Find out the operating system’s current local date and time. 69 @ingroup systime 70 @param d Returns the system’s date and time in the local time zone in a #t_datetime data structure. 71 */ 72 void systime_datetime(t_datetime *d); 73 74 75 /** 76 Find out the operating system’s time in seconds since midnight, January 1, 1904, GMT (mac HFS time). 77 @ingroup systime 78 @return the system time in seconds since midnight, January 1, 1904, GMT. 79 */ 80 t_ptr_uint systime_seconds(void); 81 82 83 /** 84 Convert a time in seconds into a #t_datetime representation. 85 @ingroup systime 86 @param secs A number of seconds since midnight, January 1, 1904, GMT, to be represented as a #t_datetime. 87 @param d The address of a #t_datetime that will be filled to the corresponding time, in the local time zone. 88 */ 89 void systime_secondstodate(t_ptr_uint secs, t_datetime *d); 90 91 92 /** 93 Convert a #t_datetime representation of time into seconds since midnight, January 1, 1904, GMT. 94 @ingroup systime 95 @param d The address of a #t_datetime to be converted to seconds. The #t_datetime values are in the local time zone. 96 @return The number of seconds between midnight, January 1, 1904, GMT and the time represented in d. 97 */ 98 t_ptr_uint systime_datetoseconds(const t_datetime *d); 99 100 101 /** 102 Fill a #t_datetime struct with a datetime formatted string. 103 For example, the string "2007-12-24 12:21:00". 104 @ingroup systime 105 @param strf A string containing the datetime. 106 @param d The address of a #t_datetime to fill. 107 */ 108 void sysdateformat_strftimetodatetime(const char *strf, t_datetime *d); 109 110 111 /** 112 Get a human friendly string representation of a #t_datetime. 113 For example: "Dec 17, 2020 at 10:48 AM" 114 or, when dateflags is SYSDATEFORMAT_RELATIVE a string like "Today", "Yesterday", etc. 115 @ingroup systime 116 @param d The address of a #t_datetime to format as a string. The t_datetime entries correspond to the local time. 117 @param dateflags One of the values defined in #e_max_dateflags. 118 @param timeflags Currently unused. Pass 0. 119 @param s An already allocated string to hold the human friendly result. 120 @param buflen The number of characters allocated to the string s. 121 */ 122 void sysdateformat_formatdatetime(const t_datetime *d, long dateflags, long timeflags, char *s, long buflen); 123 124 #if C74_PRAGMA_STRUCT_PACKPUSH 125 #pragma pack(pop) 126 #elif C74_PRAGMA_STRUCT_PACK 127 #pragma pack() 128 #endif 129 130 END_USING_C_LINKAGE 131 132 #endif // _EXT_SYSTIME_H_ 133