16b9709967f274276b48f6af206ab742c1f1d990
[hildon] / src / hildon-date-selector.c
1 /*
2  * This file is a part of hildon
3  *
4  * Copyright (C) 2005, 2008 Nokia Corporation.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version. or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 /**
22  * SECTION:hildon-date-selector
23  * @short_description: A widget to select the current date.
24  *
25  * HildonDateSelector is a date widget, equivalent to hildon-calendar, but with a multi-column
26  * approach
27  *
28  */
29
30 #define _GNU_SOURCE     /* needed for GNU nl_langinfo_l */
31 #define __USE_GNU       /* needed for locale */
32
33 #include <locale.h>
34
35 #ifdef HAVE_SYS_TIME_H
36 #include <sys/time.h>
37 #endif
38
39 #include <string.h>
40 #include <stdlib.h>
41
42 #include <libintl.h>
43 #include <time.h>
44 #include <langinfo.h>
45
46 #include "hildon-date-selector.h"
47
48 #define HILDON_DATE_SELECTOR_GET_PRIVATE(obj)                           \
49   (G_TYPE_INSTANCE_GET_PRIVATE ((obj), HILDON_TYPE_DATE_SELECTOR, HildonDateSelectorPrivate))
50
51 G_DEFINE_TYPE (HildonDateSelector, hildon_date_selector, HILDON_TYPE_TOUCH_SELECTOR)
52
53 #define INIT_YEAR 100
54 #define LAST_YEAR 50    /* since current year */
55
56 #define _(String) dgettext("hildon-libs", String)
57
58 /* #define _(String) "%A %e. %B %Y"  debug purposes */
59
60 enum
61 {
62   COLUMN_STRING,
63   COLUMN_INT,
64   N_COLUMNS
65 };
66
67 enum
68 {
69   DAY,
70   MONTH,
71   YEAR
72 };
73
74 struct _HildonDateSelectorPrivate
75 {
76   GtkTreeModel *year_model;
77   GtkTreeModel *month_model;
78   GtkTreeModel *day_model;
79
80   GSList *column_order;
81   gint day_column;
82   gint month_column;
83   gint year_column;             /* it depends on the locale */
84
85   gchar *format;                /* day/month/year format, depends on locale */
86
87   gint creation_day;
88   gint creation_month;
89   gint creation_year;           /* date at creation time */
90
91   gint current_num_days;
92 };
93
94 static void hildon_date_selector_finalize (GObject * object);
95
96 /* private functions */
97 static GtkTreeModel *_create_day_model (HildonDateSelector * selector);
98 static GtkTreeModel *_create_year_model (HildonDateSelector * selector);
99 static GtkTreeModel *_create_month_model (HildonDateSelector * selector);
100
101 static void _get_real_date (gint * year, gint * month, gint * day);
102 static void _locales_init (HildonDateSelectorPrivate * priv);
103
104 static void _manage_selector_change_cb (HildonTouchSelector * selector,
105                                         gint num_column, gpointer data);
106
107 static GtkTreeModel *_update_day_model (HildonDateSelector * selector);
108
109 static gint _month_days (gint month, gint year);
110 static void _init_column_order (HildonDateSelector * selector);
111
112 static gchar *_custom_print_func (HildonTouchSelector * selector);
113
114 /***************************************************************************/
115 /* The following date routines are taken from the lib_date package.  Keep
116  * them separate in case we want to update them if a newer lib_date comes
117  * out with fixes.  */
118
119 typedef unsigned int N_int;
120
121 typedef unsigned long N_long;
122
123 typedef signed long Z_long;
124
125 typedef enum
126 { false = FALSE, true = TRUE } boolean;
127
128 #define                                         and &&  /* logical (boolean) operators: lower case */
129
130 #define                                         or ||
131
132 static const N_int month_length[2][13] = {
133   {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
134   {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
135 };
136
137 static const N_int days_in_months[2][14] = {
138   {0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365},
139   {0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}
140 };
141
142 static Z_long _calc_days (N_int year, N_int mm, N_int dd);
143
144 static N_int _day_of_week (N_int year, N_int mm, N_int dd);
145
146 static boolean _leap (N_int year);
147
148
149 static boolean
150 _leap (N_int year)
151 {
152   return ((((year % 4) == 0) and ((year % 100) != 0)) or ((year % 400) == 0));
153 }
154
155 static N_int
156 _day_of_week (N_int year, N_int mm, N_int dd)
157 {
158   Z_long days;
159
160   days = _calc_days (year, mm, dd);
161   if (days > 0L) {
162     days--;
163     days %= 7L;
164     days++;
165   }
166   return ((N_int) days);
167 }
168
169 static Z_long
170 _year_to_days (N_int year)
171 {
172   return (year * 365L + (year / 4) - (year / 100) + (year / 400));
173 }
174
175 static Z_long
176 _calc_days (N_int year, N_int mm, N_int dd)
177 {
178   boolean lp;
179
180   if (year < 1)
181     return (0L);
182   if ((mm < 1) or (mm > 12))
183     return (0L);
184   if ((dd < 1) or (dd > month_length[(lp = _leap (year))][mm]))
185     return (0L);
186   return (_year_to_days (--year) + days_in_months[lp][mm] + dd);
187 }
188
189 static void
190 hildon_date_selector_class_init (HildonDateSelectorClass * class)
191 {
192   GObjectClass *gobject_class;
193   GtkObjectClass *object_class;
194   GtkWidgetClass *widget_class;
195   GtkContainerClass *container_class;
196
197   gobject_class = (GObjectClass *) class;
198   object_class = (GtkObjectClass *) class;
199   widget_class = (GtkWidgetClass *) class;
200   container_class = (GtkContainerClass *) class;
201
202   /* GObject */
203   gobject_class->finalize = hildon_date_selector_finalize;
204
205   /* GtkWidget */
206
207   /* GtkContainer */
208
209   /* signals */
210
211   g_type_class_add_private (object_class, sizeof (HildonDateSelectorPrivate));
212 }
213
214 static void
215 hildon_date_selector_init (HildonDateSelector * selector)
216 {
217   GSList *iter = NULL;
218   gint current_item = 0;
219   HildonTouchSelectorColumn *column = NULL;
220
221   selector->priv = HILDON_DATE_SELECTOR_GET_PRIVATE (selector);
222
223   GTK_WIDGET_SET_FLAGS (GTK_WIDGET (selector), GTK_NO_WINDOW);
224   gtk_widget_set_redraw_on_allocate (GTK_WIDGET (selector), FALSE);
225
226   hildon_touch_selector_set_print_func (HILDON_TOUCH_SELECTOR (selector),
227                                         _custom_print_func);
228
229   _locales_init (selector->priv);
230
231   _init_column_order (selector);
232
233   _get_real_date (&selector->priv->creation_year,
234                   &selector->priv->creation_month, &selector->priv->creation_day);
235
236   selector->priv->year_model = _create_year_model (selector);
237   selector->priv->month_model = _create_month_model (selector);
238   selector->priv->day_model = _create_day_model (selector);
239   selector->priv->current_num_days = 31;
240
241   /* We add the columns, checking the locale order */
242   iter = selector->priv->column_order;
243   for (iter = selector->priv->column_order; iter; iter = g_slist_next (iter)) {
244     current_item = GPOINTER_TO_INT (iter->data);
245
246     switch (current_item) {
247     case DAY:
248       column = hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector),
249                                                          selector->priv->day_model, TRUE);
250       g_object_set (G_OBJECT (column), "text-column", 0, NULL);
251       break;
252     case MONTH:
253       column = hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector),
254                                                          selector->priv->month_model, TRUE);
255       g_object_set (G_OBJECT (column), "text-column", 0, NULL);
256       break;
257     case YEAR:
258       column = hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector),
259                                                          selector->priv->year_model, TRUE);
260       g_object_set (G_OBJECT (column), "text-column", 0, NULL);
261       break;
262     default:
263       g_error ("Current column order incorrect");
264       break;
265     }
266   }
267
268   g_signal_connect (G_OBJECT (selector),
269                     "changed", G_CALLBACK (_manage_selector_change_cb), NULL);
270
271   /* By default we should select the current day */
272   hildon_date_selector_select_current_date (selector, selector->priv->creation_year,
273                                             selector->priv->creation_month,
274                                             selector->priv->creation_day);
275 }
276
277 static void
278 hildon_date_selector_finalize (GObject * object)
279 {
280   HildonDateSelector *selector = NULL;
281
282   selector = HILDON_DATE_SELECTOR (object);
283
284   g_slist_free (selector->priv->column_order);
285   g_free (selector->priv->format);
286
287   (*G_OBJECT_CLASS (hildon_date_selector_parent_class)->finalize) (object);
288 }
289
290 /* ------------------------------ PRIVATE METHODS ---------------------------- */
291 static gchar *
292 _custom_print_func (HildonTouchSelector * touch_selector)
293 {
294   HildonDateSelector *selector = NULL;
295   gchar *result = NULL;
296   guint year, month, day;
297   gint day_of_week = 0;
298   static gchar string[255];
299   struct tm tm = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
300
301   selector = HILDON_DATE_SELECTOR (touch_selector);
302
303   hildon_date_selector_get_date (selector, &year, &month, &day);
304   day_of_week = _day_of_week (year, month + 1, day) % 7;
305
306   tm.tm_mday = day;
307   tm.tm_mon = month;
308   tm.tm_year = year - 1900;
309   tm.tm_wday = day_of_week;
310
311   strftime (string, 255, _("wdgt_va_date_long"), &tm);
312
313   result = g_strdup (string);
314
315   return result;
316 }
317
318 /* This was copied from hildon-calendar */
319 static void
320 _locales_init (HildonDateSelectorPrivate * priv)
321 {
322   /* Hildon: This is not exactly portable, see
323    * http://bugzilla.gnome.org/show_bug.cgi?id=343415
324    * The labels need to be instance variables as the startup wizard changes
325    * locale on runtime.
326    */
327   locale_t l;
328
329   l = newlocale (LC_TIME_MASK, setlocale (LC_MESSAGES, NULL), NULL);
330
331   priv->format = g_locale_to_utf8 (nl_langinfo_l (D_FMT, l),
332                                    -1, NULL, NULL, NULL);
333
334   freelocale (l);
335 }
336
337 static void
338 _init_column_order (HildonDateSelector * selector)
339 {
340   gchar *current_order[3] = { NULL, NULL, NULL };
341   gchar *day_pos = NULL;
342   gchar *month_pos = NULL;
343   gchar *year_pos = NULL;
344   gint i, c;
345   gchar *aux = NULL;
346
347   g_debug ("Current format: %s", selector->priv->format);
348
349   /* search each token on the format */
350   day_pos = g_strrstr (selector->priv->format, "%d");
351
352   month_pos = g_strrstr (selector->priv->format, "%m");
353   year_pos = g_strrstr (selector->priv->format, "%y");
354   if (year_pos == NULL) {
355     year_pos = g_strrstr (selector->priv->format, "%Y");
356   }
357
358
359   if ((day_pos == NULL) || (month_pos == NULL) || (year_pos == NULL)) {
360     g_error ("Wrong date format");      /* so default values */
361
362     selector->priv->day_column = 0;
363     selector->priv->month_column = 1;
364     selector->priv->year_column = 2;
365     selector->priv->column_order = g_slist_append (NULL, GINT_TO_POINTER (DAY));
366     selector->priv->column_order =
367       g_slist_append (selector->priv->column_order, GINT_TO_POINTER (MONTH));
368     selector->priv->column_order =
369       g_slist_append (selector->priv->column_order, GINT_TO_POINTER (YEAR));
370   }
371
372   /* sort current_order with this values (bubble sort) */
373   current_order[0] = day_pos;
374   current_order[1] = month_pos;
375   current_order[2] = year_pos;
376
377   for (c = 1; c <= 2; c++) {
378     for (i = 0; i < 3 - c; i++) {
379       if (current_order[i] > current_order[i + 1]) {
380         aux = current_order[i];
381         current_order[i] = current_order[i + 1];
382         current_order[i + 1] = aux;
383       }
384     }
385   }
386
387   /* fill the column positions */
388   selector->priv->column_order = NULL;
389   c = 0;
390   for (i = 0; i < 3; i++) {
391     if (current_order[i] == day_pos) {
392       selector->priv->column_order =
393         g_slist_append (selector->priv->column_order, GINT_TO_POINTER (DAY));
394       selector->priv->day_column = c++;
395     }
396     if (current_order[i] == month_pos) {
397       selector->priv->column_order =
398         g_slist_append (selector->priv->column_order, GINT_TO_POINTER (MONTH));
399       selector->priv->month_column = c++;
400     }
401     if (current_order[i] == year_pos) {
402       selector->priv->column_order =
403         g_slist_append (selector->priv->column_order, GINT_TO_POINTER (YEAR));
404       selector->priv->year_column = c++;
405     }
406   }
407 }
408
409
410 static GtkTreeModel *
411 _create_day_model (HildonDateSelector * selector)
412 {
413   GtkListStore *store_days = NULL;
414   gint i = 0;
415   gchar label[255];
416   struct tm tm = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
417   GtkTreeIter iter;
418
419   store_days = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
420   for (i = 1; i < 32; i++) {
421     tm.tm_mday = i;
422     strftime (label, 255, _("wdgt_va_day_numeric"), &tm);
423
424     gtk_list_store_append (store_days, &iter);
425     gtk_list_store_set (store_days, &iter,
426                         COLUMN_STRING, label, COLUMN_INT, i, -1);
427   }
428
429   return GTK_TREE_MODEL (store_days);
430 }
431
432 static GtkTreeModel *
433 _create_year_model (HildonDateSelector * selector)
434 {
435   GtkListStore *store_years = NULL;
436   gint real_year = 0;
437   gint i = 0;
438   static gchar label[255];
439   struct tm tm = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
440   GtkTreeIter iter;
441
442   real_year = selector->priv->creation_year;
443
444   store_years = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
445   for (i = real_year - INIT_YEAR; i < real_year + LAST_YEAR; i++) {
446     tm.tm_year = i - 1900;
447     strftime (label, 255, _("wdgt_va_year"), &tm);
448
449     gtk_list_store_append (store_years, &iter);
450     gtk_list_store_set (store_years, &iter,
451                         COLUMN_STRING, label, COLUMN_INT, i, -1);
452   }
453
454   return GTK_TREE_MODEL (store_years);
455 }
456
457 static GtkTreeModel *
458 _create_month_model (HildonDateSelector * selector)
459 {
460   GtkTreeIter iter;
461   gint i = 0;
462   GtkListStore *store_months = NULL;
463   static gchar label[255];
464   struct tm tm = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
465
466   store_months = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
467   for (i = 0; i < 12; i++) {
468     tm.tm_mon = i;
469     strftime (label, 255, _("wdgt_va_month"), &tm);
470
471     gtk_list_store_append (store_months, &iter);
472     gtk_list_store_set (store_months, &iter, COLUMN_STRING, label,
473                         COLUMN_INT, i,
474                         -1);
475   }
476
477   return GTK_TREE_MODEL (store_months);
478 }
479
480 static GtkTreeModel *
481 _update_day_model (HildonDateSelector * selector)
482 {
483   GtkListStore *store_days = NULL;
484   GtkTreePath *path = NULL;
485   gint i = 0;
486   GtkTreeIter iter;
487   static gchar label[255];
488   struct tm tm = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
489   guint current_day = 0;
490   guint current_year = 0;
491   guint current_month = 0;
492   guint num_days = 31;
493
494   hildon_date_selector_get_date (selector, &current_year, &current_month,
495                                  &current_day);
496
497   num_days = _month_days (current_month, current_year);
498   store_days = GTK_LIST_STORE (selector->priv->day_model);
499
500   if (num_days == selector->priv->current_num_days) {
501     return GTK_TREE_MODEL (store_days);
502   }
503
504   if (num_days > selector->priv->current_num_days) {
505     for (i = selector->priv->current_num_days + 1; i <= num_days; i++) {
506       tm.tm_mday = i;
507       strftime (label, 255, _("wdgt_va_day_numeric"), &tm);
508
509       gtk_list_store_append (store_days, &iter);
510       gtk_list_store_set (store_days, &iter,
511                           COLUMN_STRING, label, COLUMN_INT, i, -1);
512     }
513   } else {
514     path = gtk_tree_path_new_from_indices (num_days,
515                                            -1);
516     gtk_tree_model_get_iter (GTK_TREE_MODEL (store_days), &iter, path);
517     do {
518     }while (gtk_list_store_remove (store_days, &iter));
519
520     gtk_tree_path_free (path);
521   }
522
523
524   selector->priv->current_num_days = num_days;
525
526   /* now we select a day */
527   if (current_day >= num_days) {
528     current_day = num_days;
529   }
530
531   hildon_date_selector_select_day (selector, current_day);
532
533   return GTK_TREE_MODEL (store_days);
534 }
535
536
537 static void
538 _get_real_date (gint * year, gint * month, gint * day)
539 {
540   time_t secs;
541   struct tm *tm = NULL;
542
543   secs = time (NULL);
544   tm = localtime (&secs);
545
546   if (year != NULL) {
547     *year = 1900 + tm->tm_year;
548   }
549
550   if (month != NULL) {
551     *month = tm->tm_mon;
552   }
553
554   if (day != NULL) {
555     *day = tm->tm_mday;
556   }
557 }
558
559
560 static void
561 _manage_selector_change_cb (HildonTouchSelector * touch_selector,
562                             gint num_column, gpointer data)
563 {
564   HildonDateSelector *selector = NULL;
565
566   g_return_if_fail (HILDON_IS_DATE_SELECTOR (touch_selector));
567   selector = HILDON_DATE_SELECTOR (touch_selector);
568
569   if ((num_column == selector->priv->month_column) ||
570       (num_column == selector->priv->year_column)) /* it is required to check that with
571                                                     * the years too,remember: leap years
572                                                     * update_day_model will check if
573                                                     * the number of days is different
574                                                     */
575   {
576     _update_day_model (selector);
577   }
578 }
579
580 static gint
581 _month_days (gint month, gint year)
582 {
583   gint month_days[2][12] = {
584     {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
585     {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
586   };
587
588   g_return_val_if_fail (month >= 0 && month <= 12, -1);
589
590   return month_days[_leap (year)][month];
591 }
592
593
594 /* ------------------------------ PUBLIC METHODS ---------------------------- */
595
596 /**
597  * hildon_date_selector_new:
598  *
599  * Creates a new #HildonDateSelector
600  *
601  * Returns: a new #HildonDateSelector
602  *
603  * Since: 2.2
604  **/
605 GtkWidget *
606 hildon_date_selector_new ()
607 {
608   return g_object_new (HILDON_TYPE_DATE_SELECTOR, NULL);
609 }
610
611
612 /**
613  * hildon_date_selector_select_current_date:
614  * @selector: the #HildonDateSelector
615  * @year:  the current year
616  * @month: the current month (0-11)
617  * @day:   the current day (1-31, 1-30, 1-29, 1-28) depends on the month
618  *
619  * Sets the current active date on the #HildonDateSelector widget
620  *
621  * Since: 2.2
622  *
623  * Returns: %TRUE on success, %FALSE otherwise
624  **/
625 gboolean
626 hildon_date_selector_select_current_date (HildonDateSelector * selector,
627                                           guint year, guint month, guint day)
628 {
629   GtkTreeIter iter;
630   gint min_year = 0;
631   gint max_year = 0;
632   gint num_days = 0;
633
634   min_year = selector->priv->creation_year - INIT_YEAR;
635   max_year = selector->priv->creation_year + LAST_YEAR;
636
637   g_return_val_if_fail (year > min_year && year < max_year, FALSE);
638   g_return_val_if_fail (month >= 0 && month < 12, FALSE);
639
640   num_days = _month_days (month, year);
641   g_return_val_if_fail (day > 0 && day <= num_days, FALSE);
642
643
644   gtk_tree_model_iter_nth_child (selector->priv->year_model, &iter, NULL,
645                                  year - selector->priv->creation_year +
646                                  INIT_YEAR);
647   hildon_touch_selector_select_iter (HILDON_TOUCH_SELECTOR (selector),
648                                      selector->priv->year_column, &iter,
649                                      FALSE);
650
651   gtk_tree_model_iter_nth_child (selector->priv->month_model, &iter, NULL,
652                                  month);
653   hildon_touch_selector_select_iter (HILDON_TOUCH_SELECTOR (selector),
654                                      selector->priv->month_column, &iter,
655                                      FALSE);
656
657   gtk_tree_model_iter_nth_child (selector->priv->day_model, &iter, NULL,
658                                  day - 1);
659   hildon_touch_selector_select_iter (HILDON_TOUCH_SELECTOR (selector),
660                                      selector->priv->day_column, &iter,
661                                      FALSE);
662
663   return TRUE;
664 }
665
666
667 /**
668  * hildon_date_selector_get_date:
669  * @selector: the #HildonDateSelector
670  * @year:  to set the current year
671  * @month: to set the current month (0-11)
672  * @day:   to the current day (1-31, 1-30, 1-29, 1-28) depends on the month
673  *
674  * Gets the current active date on the #HildonDateSelector widget
675  *
676  * Since: 2.2
677  **/
678 void
679 hildon_date_selector_get_date (HildonDateSelector * selector,
680                                guint * year, guint * month, guint * day)
681 {
682   GtkTreeIter iter;
683
684   if (year != NULL) {
685     hildon_touch_selector_get_selected (HILDON_TOUCH_SELECTOR (selector),
686                                         selector->priv->year_column, &iter);
687     gtk_tree_model_get (selector->priv->year_model,
688                         &iter, COLUMN_INT, year, -1);
689   }
690
691   if (month != NULL) {
692     hildon_touch_selector_get_selected (HILDON_TOUCH_SELECTOR (selector),
693                                         selector->priv->month_column, &iter);
694     gtk_tree_model_get (selector->priv->month_model,
695                         &iter, COLUMN_INT, month, -1);
696   }
697
698
699   if (day != NULL) {
700     if (hildon_touch_selector_get_selected (HILDON_TOUCH_SELECTOR (selector),
701                                             selector->priv->day_column, &iter))
702     {
703       gtk_tree_model_get (selector->priv->day_model,
704                           &iter, COLUMN_INT, day, -1);
705     }
706 /*       *day = *day - 1;  */
707   }
708
709 }
710
711
712 /**
713  * hildon_date_selector_select_month:
714  * @selector: the #HildonDateSelector
715  * @month: the current month (0-11)
716  * @year:  the current year
717  *
718  * Modify the current month and year on the current active date
719  *
720  * Utility function, too keep this API more similar to the previously existing
721  * hildon-calendar widget.
722  *
723  * Since: 2.2
724  *
725  * Returns: %TRUE on success, %FALSE otherwise
726  **/
727 gboolean hildon_date_selector_select_month (HildonDateSelector *selector,
728                                             guint month, guint year)
729 {
730   guint day = 0;
731
732   hildon_date_selector_get_date (selector, NULL, NULL, &day);
733
734   return hildon_date_selector_select_current_date (selector, year, month, day);
735 }
736
737 /**
738  * hildon_date_selector_select_day:
739  * @selector: the #HildonDateSelector
740  * @day:   the current day (1-31, 1-30, 1-29, 1-28) depends on the month
741  *
742  * Modify the current day on the current active date
743  *
744  * Utility function, too keep this API more similar to the previously existing
745  * hildon-calendar widget.
746  *
747  * Since: 2.2
748  **/
749 void
750 hildon_date_selector_select_day (HildonDateSelector *selector, guint day)
751 {
752   guint month = 0;
753   guint year = 0;
754
755   hildon_date_selector_get_date (selector, &year, &month, NULL);
756
757   hildon_date_selector_select_current_date (selector, year, month, day);
758 }