From 93f68f2bc009ec7a245a0adf7baeceae17dd3f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Sun, 11 Jun 2023 19:35:46 -0300 Subject: :datefmt does not remove text content anymore allowing future edition - work on item 3 of issue 769 --- CHANGES | 36 ++++++++++++++++++++++++------------ src/doc | 53 +++++++++++++++++++++++++++++++++++++++-------------- src/interp.c | 21 ++++++++++++++++++--- src/tui.c | 19 +++++++++++++++++-- 4 files changed, 98 insertions(+), 31 deletions(-) diff --git a/CHANGES b/CHANGES index b3e0211..53ac406 100644 --- a/CHANGES +++ b/CHANGES @@ -1,9 +1,31 @@ CHANGES FILE ------------ + + +Please open a discussion on GitHub to comment on these and other feature requests. + +*********** +v0.8.4 +06/12/2023: :datefmt does not remove text content anymore allowing future edition - work on item 3 of issue 769 +06/11/2023: avoid changing cell's color after :format - issue 819 +06/11/2023: avoid blanking cell's text content after :datefmt - issue 769 +06/10/2023: fix number 2 of issue 769 +06/02/2023: fix configuration variable name in file.c: import_delimited_to_text +06/01/2023: restore transpose +06/01/2023: added input_edit_mode setting PR 626 +06/01/2023: work on issue 708: xlsx file import +06/01/2023: Fix issue 784: get row number and column or cell that calls a LUA script with PR 814. +06/01/2023: merged PR 783 that gets rid of issue 778 - changed load_rc load_file order. +06/01/2023: merged PR 776 +06/01/2023: merged PR 789 +06/01/2023: fix issue in csv import - 816 + + + Ideas for v0.8.5 ---------------- -+ restore transpose + + Add is_deleted flag on sheets that are deleted. So ents have a chance to update its references to that sheet. Then rebuild graph. + arv should have priority over scimrc. @@ -17,19 +39,9 @@ this could allow future use of registers to copy to and paste from. -Please open a discussion on GitHub to comment on these and other feature requests. -*********** -v0.8.4 -06/02/2023: fix configuration variable name in file.c: import_delimited_to_text -06/01/2023: added input_edit_mode setting PR 626 -06/01/2023: work on issue 708: xlsx file import -06/01/2023: Fix issue 784: get row number and column or cell that calls a LUA script with PR 814. -06/01/2023: merged PR 783 that gets rid of issue 778 - changed load_rc load_file order. -06/01/2023: merged PR 776 -06/01/2023: merged PR 789 -06/01/2023: fix issue in csv import - 816 + *********** diff --git a/src/doc b/src/doc index 03ecdf2..2a4d2c7 100755 --- a/src/doc +++ b/src/doc @@ -1233,22 +1233,47 @@ Commands for handling cell content: Dates are internally stored in sc-im as numeric values, and they are displayed as dates if a date format is applied to the cells that store - them. You have 3 options for entering them: + them. You have 3 options for entering dates: 1. Dates can be entered as text and then converted to a numeric - value with the :datefmt command. - - The :datefmt command takes the cell's text content that represents a date, - and uses a given format to set the numeric value of the cell. - Its format is ':datefmt "{strftime_format}"', taking a strftime-compatible - format string. The format is applied to the cell (as could be done with - the :format function) so that the value is displayed as a date. - - Example: \12/03/2020 - :datefmt "%d/%m/%Y" - - NOTE: The command, used in NORMAL and VISUAL modes, acts as the - `:datefmt` described above, but uses the locale's D_FMT format. + value with or with the :datefmt command. + + a. With keybinding: + The command works on NORMAL and VISUAL modes, and converts + cell's text content that represents a date, and sets the numeric + value of the cell using using locale's D_FMT format. + After convertion, the same format is applied automatically to the + cell so that the value is displayed as a date. + You can then change the date format with :format command or + just leave it as it is with the current locale D_FMT format. + + Example: + \03/04/1984 + + :format "d %b %Y" + will output 'Mar 1984' with my current locale. + + NOTES: + You can edit the date value by changing the text content + of the cell with 'E' command. + + To get current locale's D_FMT format, you might want to + issue ``locale -k d_fmt`` on your current shell. + + + b. With :datefmt command: + This command works like but instead of using locale's D_FMT + format for convertion, it takes a strftime-compatible format string as + a parameter. Its syntax is ':datefmt "{strftime_format}"' + After convertion, the same format is applied automatically to the cell + so that the value is displayed as a date. + + Example: \12/03/2020 + :datefmt "%d/%m/%Y" + + NOTE: Take note here that if you edit the date with the 'E' command, + sc-im will nevertheless convert the date using locale's D_FMT format + and not the one you used with datefmt. + You will need to reapply :datefmt "%d/%m/%Y" or whatever format + you used earlier to reapply the format after the modification. 2. You can also enter dates using the @date and @dts functions. Example: \"@date(@dts(2015, 23, 2), "%d/%m/%Y") diff --git a/src/interp.c b/src/interp.c index b67b3fc..a8a1656 100644 --- a/src/interp.c +++ b/src/interp.c @@ -1604,10 +1604,24 @@ void slet(struct roman * roman, struct sheet * sh, struct ent * v, struct enode if (v->format && v->format[0] == 'd') { struct tm tm; memset(&tm, 0, sizeof(struct tm)); - strptime(v->label, &v->format[1], &tm); + + // change for number 3 of issue 769: + // reconvert numeric value based on locale's D_FMT format instead of current format + char * f = &v->format[1]; + #ifdef USELOCALE + #include + #include + char * loc = NULL; + f = NULL; + loc = setlocale(LC_TIME, ""); + if (loc != NULL) f = nl_langinfo(D_FMT); + #endif + // reconvert numeric value based on locale's D_FMT format instead of current format + strptime(v->label, f, &tm); v->v = (double) mktime(&tm); v->flags |= ( is_changed | is_valid ); - label(v, "", -1); // free label + //commented for number 3 of issue 769 + //label(v, "", -1); // free label } } else { if (p) free(p); // This prevents leaks in string formulas - missing in old sc @@ -2351,7 +2365,8 @@ int dateformat(struct sheet * sh, struct ent *v1, struct ent *v2, char * fmt) { strptime((n)->label, fmt, &tm); n->v = (double) mktime(&tm); n->flags |= ( is_changed | is_valid ); - label(n, "", -1); // free label + //commented for number 3 of issue 769 + //label(n, "", -1); // free label // agrego formato de fecha n->format = 0; diff --git a/src/tui.c b/src/tui.c index 6e9c786..2b033f2 100644 --- a/src/tui.c +++ b/src/tui.c @@ -1007,6 +1007,10 @@ int ui_show_content(WINDOW * win, int nb_mobile_rows, int nb_mobile_cols) { // else if get_conf_int("hide_number_from_combined")) // num[0]='\0'; // } + // + // AVOID showing text content and date formated numeric value both at the same time - number 3 of issue 769 + if ((*p) && (*p)->format && (*p)->format[0] == 'd') text[0]='\0'; + pad_and_align(text, num, fieldlen, align, (*p)->pad, out, sh->row_format[row]); #ifdef USECOLORS @@ -1087,6 +1091,17 @@ int ui_show_content(WINDOW * win, int nb_mobile_rows, int nb_mobile_cols) { void ui_add_cell_detail(char * d, struct ent * p1) { if ( ! p1 ) return; + /* show date if date value + if (p1->format && p1->format[0] == 'd') { // date format + strcat(d, "["); + time_t v = (time_t) p1->v; + char dvalue[FBUFLEN] = ""; + strftime(dvalue, sizeof(char) * FBUFLEN, p1->format+1, localtime(&v)); + strcat(d, dvalue); + strcat(d, "] "); + } + */ + /* string expressions if (p1->expr && (p1->flags & is_strexpr)) { if (p1->flags & is_label) @@ -1095,7 +1110,7 @@ void ui_add_cell_detail(char * d, struct ent * p1) { strcat(d, (p1->flags & is_leftflush) ? "<{" : ">{"); strcat(d, "??? } "); // and this '}' is for vi % - } else*/ + } else */ if (p1->label) { /* has constant label only */ @@ -1251,7 +1266,7 @@ void yyerror(char * err) { * \param[in] err * \return 0 datetime format - number in p->v represents a date - format "d" - * \return 1 if format of number - (numbers with format) - puede harber label. + * \return 1 if format of number - (numbers with format) - (label can exists) * \return -1 if there is no format in the cell */ int ui_get_formated_value(struct ent ** p, int col, char * value) { -- cgit v1.2.3