diff options
-rwxr-xr-x | ChangeLog | 11 | ||||
-rwxr-xr-x | TODO | 1 | ||||
-rwxr-xr-x | src/custom.c | 12 | ||||
-rwxr-xr-x | src/io.c | 5 | ||||
-rwxr-xr-x | src/utils.c | 43 | ||||
-rwxr-xr-x | src/vars.h | 25 |
6 files changed, 70 insertions, 27 deletions
@@ -1,3 +1,14 @@ +2009-01-05 Frederic Culot <frederic@culot.org> + + * src/custom.c (custom_general_config, print_general_options): + iso date format (yyyy-mm-dd) added + + * src/utils.c (parse_date) + * src/custom.c (custom_load_conf) + * src/io.c (io_save_cal): iso date format added + + * TODO: updated + 2009-01-04 Frederic Culot <frederic@culot.org> * src/help.c (help_screen): help page added to describe the cut @@ -26,5 +26,4 @@ Average Low --- - o Improve the '-d' option by adding more date formats o All status bars should be terminal-size dependant (config_bar is not) diff --git a/src/custom.c b/src/custom.c index 1d29894..0478247 100755 --- a/src/custom.c +++ b/src/custom.c @@ -1,4 +1,4 @@ -/* $calcurse: custom.c,v 1.35 2009/01/03 21:32:11 culot Exp $ */ +/* $calcurse: custom.c,v 1.36 2009/01/05 20:12:08 culot Exp $ */ /* * Calcurse - text-based organizer @@ -303,7 +303,7 @@ custom_load_conf (conf_t *conf, int background) break; case CUSTOM_CONF_INPUTDATEFMT: conf->input_datefmt = atoi (e_conf); - if (conf->input_datefmt < 1 || conf->input_datefmt > 3) + if (conf->input_datefmt <= 0 || conf->input_datefmt >= DATE_FORMATS) conf->input_datefmt = 1; var = 0; break; @@ -941,7 +941,8 @@ print_general_options (WINDOW *win, conf_t *conf) conf->input_datefmt); custom_remove_attr (win, ATTR_HIGHEST); mvwprintw (win, y + 1, XPOS, _("(Format to be used when entering a date: ")); - mvwprintw (win, y + 2, XPOS, _(" 1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd)")); + mvwprintw (win, y + 2, XPOS, + _(" (1)mm/dd/yyyy (2)dd/mm/yyyy (3)yyyy/mm/dd (4)yyyy-mm-dd)")); return y + YOFF; } @@ -972,7 +973,8 @@ custom_general_config (conf_t *conf) char *output_datefmt_str = _("Enter the date format (see 'man 3 strftime' for possible formats) "); char *input_datefmt_str = - _("Enter the date format (1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) "); + _("Enter the date format (1)mm/dd/yyyy (2)dd/mm/yyyy (3)yyyy/mm/dd " + "(4)yyyy-mm-dd"); char *periodic_save_str = _("Enter the delay, in minutes, between automatic saves (0 to disable) "); int ch; @@ -1066,7 +1068,7 @@ custom_general_config (conf_t *conf) if (updatestring (win[STA].p, &buf, 0, 1) == 0) { int val = atoi (buf); - if (val >= 1 && val <= 3) + if (val > 0 && val <= DATE_FORMATS) conf->input_datefmt = val; } status_mesg (number_str, keys); @@ -1,4 +1,4 @@ -/* $calcurse: io.c,v 1.55 2009/01/03 21:32:11 culot Exp $ */ +/* $calcurse: io.c,v 1.56 2009/01/05 20:12:08 culot Exp $ */ /* * Calcurse - text-based organizer @@ -908,7 +908,8 @@ io_save_cal (conf_t *conf, io_save_display_t display) (void)fprintf (data_file, "\n# Format to be used when entering a date " - "(1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) :\n"); + "(1)mm/dd/yyyy (2)dd/mm/yyyy (3)yyyy/mm/dd) " + "(4)yyyy-mm-dd:\n"); (void)fprintf (data_file, "input_datefmt=\n"); (void)fprintf (data_file, "%d\n", conf->input_datefmt); diff --git a/src/utils.c b/src/utils.c index d739e6c..561b78e 100755 --- a/src/utils.c +++ b/src/utils.c @@ -1,4 +1,4 @@ -/* $calcurse: utils.c,v 1.66 2009/01/03 21:32:11 culot Exp $ */ +/* $calcurse: utils.c,v 1.67 2009/01/05 20:12:08 culot Exp $ */ /* * Calcurse - text-based organizer @@ -815,40 +815,57 @@ parse_date (char *date_string, int datefmt, int *year, int *month, int *day) { int in1, in2, in3; int lyear, lmonth, lday; - if (date_string == NULL) - return (0); - if (sscanf (date_string, "%d / %d / %d", &in1, &in2, &in3) < 3) - return (0); + + if (date_string == 0) + return 0; + + if (datefmt == DATEFMT_ISO) + { + if (sscanf (date_string, "%d - %d - %d", &in1, &in2, &in3) < 3) + return 0; + } + else + { + if (sscanf (date_string, "%d / %d / %d", &in1, &in2, &in3) < 3) + return 0; + } switch (datefmt) { - case 1: + case DATEFMT_MMDDYYYY: lmonth = in1; lday = in2; lyear = in3; break; - case 2: + case DATEFMT_DDMMYYYY: lday = in1; lmonth = in2; lyear = in3; break; - case 3: + case DATEFMT_YYYYMMDD: + case DATEFMT_ISO: lyear = in1; lmonth = in2; lday = in3; break; default: - return (0); + return 0; } - if (lyear < 1 || lyear > 9999 || lmonth < 1 || lmonth > 12 || lday < 1 - || lday > 31) - return (0); + + if (lyear < 1 || lyear > 9999 + || lmonth < 1 || lmonth > 12 + || lday < 1 || lday > 31) + return 0; + if (year != NULL) *year = lyear; + if (month != NULL) *month = lmonth; + if (day != NULL) *day = lday; - return (1); + + return 1; } char * @@ -1,4 +1,4 @@ -/* $calcurse: vars.h,v 1.29 2009/01/02 22:28:54 culot Exp $ */ +/* $calcurse: vars.h,v 1.30 2009/01/05 20:12:08 culot Exp $ */ /* * Calcurse - text-based organizer @@ -59,11 +59,24 @@ #define STATUSHEIGHT 2 #define NOTESIZ 6 -#define DATEFMT(datefmt) (datefmt == 1 ? "%m/%d/%Y" : \ - (datefmt == 2 ? "%d/%m/%Y" : "%Y/%m/%d")) +enum { + DATEFMT_MMDDYYYY = 1, + DATEFMT_DDMMYYYY, + DATEFMT_YYYYMMDD, + DATEFMT_ISO, + DATE_FORMATS +}; + +#define DATEFMT(datefmt) (datefmt == DATEFMT_MMDDYYYY ? "%m/%d/%Y" : \ + (datefmt == DATEFMT_DDMMYYYY ? "%d/%m/%Y" : \ + (datefmt == DATEFMT_YYYYMMDD ? "%Y/%m/%d" : "%Y-%m-%d"))) -#define DATEFMT_DESC(datefmt) (datefmt == 1 ? _("mm/dd/yyyy") : \ - (datefmt == 2 ? _("dd/mm/yyyy") : _("yyyy/mm/dd"))) +#define DATEFMT_DESC(datefmt) (datefmt == DATEFMT_MMDDYYYY ? \ + _("mm/dd/yyyy") : \ + (datefmt == DATEFMT_DDMMYYYY ? \ + _("dd/mm/yyyy") : \ + (datefmt == DATEFMT_YYYYMMDD ? \ + _("yyyy/mm/dd") : _("yyyy-mm-dd")))) typedef enum { UI_CURSES, @@ -122,6 +135,6 @@ extern char path_notes[BUFSIZ]; extern struct pad_s apad; extern struct nbar_s nbar; -void vars_init (conf_t *conf); +void vars_init (conf_t *); #endif /* CALCURSE_VARS_H */ |