99#pragma GCC diagnostic ignored "-Wformat" // warning: unknown conversion type character 'F' in format
1010
1111#define FF_DATETIME_DISPLAY_NAME "Date & Time"
12- #define FF_DATETIME_NUM_FORMAT_ARGS 20
12+ #define FF_DATETIME_NUM_FORMAT_ARGS 22
1313
1414typedef struct FFDateTimeResult
1515{
1616 //Examples for 21.02.2022 - 15:18:37
1717 uint16_t year ; //2022
1818 uint8_t yearShort ; //22
1919 uint8_t month ; //2
20- FFstrbuf monthPretty ; //02
21- FFstrbuf monthName ; //February
22- FFstrbuf monthNameShort ; //Feb
20+ char monthPretty [ FASTFETCH_STRBUF_DEFAULT_ALLOC ] ; //02
21+ char monthName [ FASTFETCH_STRBUF_DEFAULT_ALLOC ] ; //February
22+ char monthNameShort [ FASTFETCH_STRBUF_DEFAULT_ALLOC ] ; //Feb
2323 uint8_t week ; //8
24- FFstrbuf weekday ; //Monday
25- FFstrbuf weekdayShort ; //Mon
24+ char weekday [ FASTFETCH_STRBUF_DEFAULT_ALLOC ] ; //Monday
25+ char weekdayShort [ FASTFETCH_STRBUF_DEFAULT_ALLOC ] ; //Mon
2626 uint16_t dayInYear ; //52
2727 uint8_t dayInMonth ; //21
2828 uint8_t dayInWeek ; //1
2929 uint8_t hour ; //15
30- FFstrbuf hourPretty ; //15
30+ char hourPretty [ FASTFETCH_STRBUF_DEFAULT_ALLOC ] ; //15
3131 uint8_t hour12 ; //3
32- FFstrbuf hour12Pretty ; //03
32+ char hour12Pretty [ FASTFETCH_STRBUF_DEFAULT_ALLOC ] ; //03
3333 uint8_t minute ; //18
34- FFstrbuf minutePretty ; //18
34+ char minutePretty [ FASTFETCH_STRBUF_DEFAULT_ALLOC ] ; //18
3535 uint8_t second ; //37
36- FFstrbuf secondPretty ; //37
36+ char secondPretty [FASTFETCH_STRBUF_DEFAULT_ALLOC ]; //37
37+ char offsetFromUtc [FASTFETCH_STRBUF_DEFAULT_ALLOC ];
38+ char timezoneName [FASTFETCH_STRBUF_DEFAULT_ALLOC ];
3739} FFDateTimeResult ;
3840
3941void ffPrintDateTimeFormat (struct tm * tm , const FFModuleArgs * moduleArgs )
@@ -43,80 +45,50 @@ void ffPrintDateTimeFormat(struct tm* tm, const FFModuleArgs* moduleArgs)
4345 result .year = (uint16_t ) (tm -> tm_year + 1900 );
4446 result .yearShort = (uint8_t ) (result .year % 100 );
4547 result .month = (uint8_t ) (tm -> tm_mon + 1 );
46-
47- ffStrbufInitA (& result .monthPretty , FASTFETCH_STRBUF_DEFAULT_ALLOC );
48- result .monthPretty .length = (uint32_t ) strftime (result .monthPretty .chars , ffStrbufGetFree (& result .monthPretty ), "%m" , tm );
49-
50- ffStrbufInitA (& result .monthName , FASTFETCH_STRBUF_DEFAULT_ALLOC );
51- result .monthName .length = (uint32_t ) strftime (result .monthName .chars , ffStrbufGetFree (& result .monthName ), "%B" , tm );
52-
53- ffStrbufInitA (& result .monthNameShort , FASTFETCH_STRBUF_DEFAULT_ALLOC );
54- result .monthNameShort .length = (uint32_t ) strftime (result .monthNameShort .chars , ffStrbufGetFree (& result .monthNameShort ), "%b" , tm );
55-
48+ strftime (result .monthPretty , sizeof (result .monthPretty ), "%m" , tm );
49+ strftime (result .monthName , sizeof (result .monthName ), "%B" , tm );
50+ strftime (result .monthNameShort , sizeof (result .monthNameShort ), "%b" , tm );
5651 result .week = (uint8_t ) (tm -> tm_yday / 7 + 1 );
57-
58- ffStrbufInitA (& result .weekday , FASTFETCH_STRBUF_DEFAULT_ALLOC );
59- result .weekday .length = (uint32_t ) strftime (result .weekday .chars , ffStrbufGetFree (& result .weekday ), "%A" , tm );
60-
61- ffStrbufInitA (& result .weekdayShort , FASTFETCH_STRBUF_DEFAULT_ALLOC );
62- result .weekdayShort .length = (uint32_t ) strftime (result .weekdayShort .chars , ffStrbufGetFree (& result .weekdayShort ), "%a" , tm );
63-
52+ strftime (result .weekday , sizeof (result .weekday ), "%A" , tm );
53+ strftime (result .weekdayShort , sizeof (result .weekdayShort ), "%a" , tm );
6454 result .dayInYear = (uint8_t ) (tm -> tm_yday + 1 );
6555 result .dayInMonth = (uint8_t ) tm -> tm_mday ;
6656 result .dayInWeek = tm -> tm_wday == 0 ? 7 : (uint8_t ) tm -> tm_wday ;
67-
6857 result .hour = (uint8_t ) tm -> tm_hour ;
69-
70- ffStrbufInitA (& result .hourPretty , FASTFETCH_STRBUF_DEFAULT_ALLOC );
71- result .hourPretty .length = (uint32_t ) strftime (result .hourPretty .chars , ffStrbufGetFree (& result .hourPretty ), "%H" , tm );
72-
58+ strftime (result .hourPretty , sizeof (result .hourPretty ), "%H" , tm );
7359 result .hour12 = (uint8_t ) (result .hour % 12 );
74-
75- ffStrbufInitA (& result .hour12Pretty , FASTFETCH_STRBUF_DEFAULT_ALLOC );
76- result .hour12Pretty .length = (uint32_t ) strftime (result .hour12Pretty .chars , ffStrbufGetFree (& result .hour12Pretty ), "%I" , tm );
77-
60+ strftime (result .hour12Pretty , sizeof (result .hour12Pretty ), "%I" , tm );
7861 result .minute = (uint8_t ) tm -> tm_min ;
79-
80- ffStrbufInitA (& result .minutePretty , FASTFETCH_STRBUF_DEFAULT_ALLOC );
81- result .minutePretty .length = (uint32_t ) strftime (result .minutePretty .chars , ffStrbufGetFree (& result .minutePretty ), "%M" , tm );
82-
62+ strftime (result .minutePretty , sizeof (result .minutePretty ), "%M" , tm );
8363 result .second = (uint8_t ) tm -> tm_sec ;
84-
85- ffStrbufInitA ( & result .secondPretty , FASTFETCH_STRBUF_DEFAULT_ALLOC );
86- result . secondPretty . length = ( uint32_t ) strftime (result .secondPretty . chars , ffStrbufGetFree ( & result .secondPretty ), "%S " , tm );
64+ strftime ( result . secondPretty , sizeof ( result . secondPretty ), "%S" , tm );
65+ strftime ( result .offsetFromUtc , sizeof ( result . offsetFromUtc ), "%z" , tm );
66+ strftime (result .timezoneName , sizeof ( result .timezoneName ), "%Z " , tm );
8767
8868 ffPrintFormat (FF_DATETIME_DISPLAY_NAME , 0 , moduleArgs , FF_DATETIME_NUM_FORMAT_ARGS , (FFformatarg []) {
8969 {FF_FORMAT_ARG_TYPE_UINT16 , & result .year }, // 1
9070 {FF_FORMAT_ARG_TYPE_UINT8 , & result .yearShort }, // 2
9171 {FF_FORMAT_ARG_TYPE_UINT8 , & result .month }, // 3
92- {FF_FORMAT_ARG_TYPE_STRBUF , & result .monthPretty }, // 4
93- {FF_FORMAT_ARG_TYPE_STRBUF , & result .monthName }, // 5
94- {FF_FORMAT_ARG_TYPE_STRBUF , & result .monthNameShort }, // 6
72+ {FF_FORMAT_ARG_TYPE_STRING , result .monthPretty }, // 4
73+ {FF_FORMAT_ARG_TYPE_STRING , result .monthName }, // 5
74+ {FF_FORMAT_ARG_TYPE_STRING , result .monthNameShort }, // 6
9575 {FF_FORMAT_ARG_TYPE_UINT8 , & result .week }, // 7
96- {FF_FORMAT_ARG_TYPE_STRBUF , & result .weekday }, // 8
97- {FF_FORMAT_ARG_TYPE_STRBUF , & result .weekdayShort }, // 9
76+ {FF_FORMAT_ARG_TYPE_STRING , result .weekday }, // 8
77+ {FF_FORMAT_ARG_TYPE_STRING , result .weekdayShort }, // 9
9878 {FF_FORMAT_ARG_TYPE_UINT16 , & result .dayInYear }, // 10
9979 {FF_FORMAT_ARG_TYPE_UINT8 , & result .dayInMonth }, // 11
10080 {FF_FORMAT_ARG_TYPE_UINT8 , & result .dayInWeek }, // 12
10181 {FF_FORMAT_ARG_TYPE_UINT8 , & result .hour }, // 13
102- {FF_FORMAT_ARG_TYPE_STRBUF , & result .hourPretty }, // 14
82+ {FF_FORMAT_ARG_TYPE_STRING , result .hourPretty }, // 14
10383 {FF_FORMAT_ARG_TYPE_UINT8 , & result .hour12 }, // 15
104- {FF_FORMAT_ARG_TYPE_STRBUF , & result .hour12Pretty }, // 16
84+ {FF_FORMAT_ARG_TYPE_STRING , result .hour12Pretty }, // 16
10585 {FF_FORMAT_ARG_TYPE_UINT8 , & result .minute }, // 17
106- {FF_FORMAT_ARG_TYPE_STRBUF , & result .minutePretty }, // 18
86+ {FF_FORMAT_ARG_TYPE_STRING , result .minutePretty }, // 18
10787 {FF_FORMAT_ARG_TYPE_UINT8 , & result .second }, // 19
108- {FF_FORMAT_ARG_TYPE_STRBUF , & result .secondPretty } // 20
88+ {FF_FORMAT_ARG_TYPE_STRING , result .secondPretty }, // 20
89+ {FF_FORMAT_ARG_TYPE_STRING , result .offsetFromUtc }, // 21
90+ {FF_FORMAT_ARG_TYPE_STRING , result .timezoneName }, // 22
10991 });
110-
111- ffStrbufDestroy (& result .hour12Pretty );
112- ffStrbufDestroy (& result .hourPretty );
113- ffStrbufDestroy (& result .minutePretty );
114- ffStrbufDestroy (& result .monthName );
115- ffStrbufDestroy (& result .monthNameShort );
116- ffStrbufDestroy (& result .monthPretty );
117- ffStrbufDestroy (& result .secondPretty );
118- ffStrbufDestroy (& result .weekday );
119- ffStrbufDestroy (& result .weekdayShort );
12092}
12193
12294void ffPrintDateTime (FFDateTimeOptions * options )
@@ -205,7 +177,9 @@ void ffPrintDateTimeHelpFormat(void)
205177 "minute" ,
206178 "minute with leading zero" ,
207179 "second" ,
208- "second with leading zero"
180+ "second with leading zero" ,
181+ "offset from UTC in the ISO 8601 format" ,
182+ "locale-dependent timezone name or abbreviation" ,
209183 });
210184}
211185
0 commit comments