

In this simple example, we\textquotesingle{}ll explain how to format the label displaying month and year, and also set weekday names.

To format month and year label, we need to create a callback function to create a string given the selected time, declared under a {\ttfamily  struct tm }.

{\ttfamily  struct tm }, declared on {\ttfamily time.\+h}, is a structure composed by nine integers\+: \begin{DoxyItemize}
\item tm\+\_\+sec seconds \mbox{[}0,59\mbox{]} \item tm\+\_\+min minutes \mbox{[}0,59\mbox{]} \item tm\+\_\+hour hour \mbox{[}0,23\mbox{]} \item tm\+\_\+mday day of month \mbox{[}1,31\mbox{]} \item tm\+\_\+mon month of year \mbox{[}0,11\mbox{]} \item tm\+\_\+year years since 1900 \item tm\+\_\+wday day of week \mbox{[}0,6\mbox{]} (Sunday = 0) \item tm\+\_\+yday day of year \mbox{[}0,365\mbox{]} \item tm\+\_\+isdst daylight savings flag \begin{DoxyNote}{Note}
glib version has 2 additional fields.
\end{DoxyNote}
For our function, only stuff that matters are tm\+\_\+mon and tm\+\_\+year. But we don\textquotesingle{}t need to access it directly, since there are nice functions to format date and time, as {\ttfamily strftime}. We will get abbreviated month (b) and year (y) (check strftime manpage for more) in our example\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{char} *}
\DoxyCodeLine{\_format\_month\_year(\textcolor{keyword}{struct} tm *format\_time)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keywordtype}{char} buf[32];}
\DoxyCodeLine{   \textcolor{comment}{/* abbreviates month and year */}}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!strftime(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"{}\%b \%y"{}}, format\_time)) \textcolor{keywordflow}{return} NULL;}
\DoxyCodeLine{   \textcolor{keywordflow}{return} strdup(buf);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 We need to alloc the string to be returned, and calendar widget will free it when it\textquotesingle{}s not needed, what is done by {\ttfamily strdup}. So let\textquotesingle{}s register our callback to calendar object\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   elm\_calendar\_format\_function\_set(cal, \_format\_month\_year);}

\end{DoxyCodeInclude}
 To set weekday names, we should declare them as an array of strings\+:  
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *weekdays[] =}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \textcolor{stringliteral}{"{}S"{}}, \textcolor{stringliteral}{"{}M"{}}, \textcolor{stringliteral}{"{}T"{}}, \textcolor{stringliteral}{"{}W"{}}, \textcolor{stringliteral}{"{}T"{}}, \textcolor{stringliteral}{"{}F"{}}, \textcolor{stringliteral}{"{}S"{}}}
\DoxyCodeLine{     \};}

\end{DoxyCodeInclude}
 And finally set them to calendar\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   elm\_calendar\_weekdays\_names\_set(cal, weekdays);}

\end{DoxyCodeInclude}
 Our example will look like this\+:\end{DoxyItemize}
 
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{screenshots/calendar_example_02}}
\end{DoxyImageNoCaption}


See the full source code \mbox{\hyperlink{calendar_example_02_8c-example}{calendar\+\_\+example\+\_\+02.\+c}} here. 