andmarti1424 / sc-im

sc-im - Spreadsheet Calculator Improvised -- An ncurses spreadsheet program for terminal
Other
4.77k stars 201 forks source link

Date handling in Markdown export #875

Open cskeeters opened 1 month ago

cskeeters commented 1 month ago

If a cell has a number representing a date and a label (for future E <c-d>), the cell of the markdown exported table outputs the label instead of the formatted date and appears to have two years in it. I'd prefer the formatted date as show to the user in sc-im.

In the example:

The same date format was applied to all three dates. (:format \"d%b-%Y\")

date-mkd.sc

# This data file was generated by the Spreadsheet Calculator Improvised (sc-im)
# You almost certainly shouldn't edit it.

newsheet "Sheet1"
movetosheet "Sheet1"
offscr_sc_cols 0
offscr_sc_rows 0
nb_frozen_rows 0
nb_frozen_cols 0
nb_frozen_screenrows 0
nb_frozen_screencols 0
leftstring A0 = "Date"
leftstring B0 = "Now"
leftstring C0 = "Value"
label A1 = "3/5/2024"
let A1 = 1709618400
fmt A1 "d%b-%Y"
let B1 = @now
fmt B1 "d%b-%Y"
let C1 = 1719769640
fmt C1 "d%b-%Y"
goto C0

date-mkd.mkd

| Date       | Now        | Value      |
|------------|------------|------------|
| 3/5/202424 |   Jun-2024 |   Jun-2024 |
marrs commented 1 month ago

I wasn't able to reproduce your issue. Instead I got the following date-mkd.mkd on running e! mkd:

| Date           | Now        | Value      |
|----------------|------------|------------|
| ************** |   Jul-2024 |   Jun-2024 |

Is there anything else I should do to reproduce your result?

cskeeters commented 1 month ago

I'm running on MacOS Sonoma 14.3.1 (23D60). I installed sc-im with:

brew install --head sc-im

After some further testing, if I make the A column wider (30fl) within sc-im, and re-export the markdown, I get the label centered and the formatted date on the right. It just dawned on me that there might be a correlation between the width of the columns in the sheet and the exported table. That's something worth noting. I had previously guessed it would calculate the widest exported text for that column and make it that width.

Within sc-im, the cell only displays the formatted date on the right. I think that's what I would prefer to see in the mkd output.

| Date                                   | Now        | Value      |
|----------------------------------------|------------|------------|
|                3/5/2024       Mar-2024 |   Jul-2024 |   Jun-2024 |
marrs commented 1 month ago

I can't reproduce that either! I just see the formatted date in A1.

Btw, I'm not a maintainer or anything. I was just troubleshooting a possibly related bug of my own.

cskeeters commented 1 month ago

To be clear, I see only the formatted date in A1 from within sc-im. In the mkd file that results from e! mkd, I see a centered text with the date label and the formatted date on the right of the cell that would correspond to A1. You don't see that?

marrs commented 1 month ago

Ah, I misunderstood. Yes, I do see that. In that case, it might be related to my bug. I can fix it with the following patch:

diff --git a/src/file.c b/src/file.c
index 40c0cfd..fafa2d3 100644
--- a/src/file.c
+++ b/src/file.c
@@ -1541,7 +1541,7 @@ void export_markdown(char * fname, int r0, int c0, int rn, int cn) {
                     }

                     // If a string exists
-                    if ((*pp)->label) {
+                    if ((*pp)->v == '\0' && (*pp)->label) {
                         strcpy(text, (*pp)->label);
                         align = 1;                                // right alignment
                         if ((*pp)->flags & is_label) {            // center alignment

which is the same as what I did for #879. FYI @andmarti1424

marrs commented 1 month ago

I think the not-enough-room formatting is also a bug. The fact there was enough room for the date when viewing in sc-im directly suggests there should be enough room to show it in the markdown version.