Commit db7bbc5
authored
fix: use NumberValue to calculate datetime instead of parsing (#379)
**What**:
This PR makes use of the the locale-independent `NumberValue` (decimal
datetime value) from the Google Sheets API instead of parsing the
locale-dependent `FormattedValue` string.
The decimal datetime value stores dates as decimal numbers where:
- Integer part = days since December 30, 1899
- Fractional part = time of day (for DATE_TIME types)
This is documented in the [Google Sheets API formats
guide](https://developers.google.com/workspace/sheets/api/guides/formats)
It maintains a fallback to the old parsing in case `NumberValue` is
missing (this is unexpected and we can consider returning an error if we
want to be a bit strict).
Some examples:
Unhinged custom date/time formatting:
<img width="165" height="72" alt="Screenshot 2025-12-04 at 17 16 49"
src="https://github.com/user-attachments/assets/c8923ae9-fa40-475d-8ce2-ce7c4a39b807"
/>
This PR would render the above as (note that I set time to UTC +2):
<img width="162" height="113" alt="Screenshot 2025-12-04 at 16 21 54"
src="https://github.com/user-attachments/assets/c6c38c66-80d3-4479-88b8-c3f07f6e5296"
/>
**Why**:
The original implementation used `dateparse.ParseLocal()` to parse the
`FormattedValue` string (e.g., "1/5/2020" or "5/1/2020"), which caused
different date interpretations depending on the server's locale
settings.
For example, A date displayed as "1/5/2020" could be parsed as January
5th instead of the May 1st.
**Fixes**:
Fixes #1231 parent d077435 commit db7bbc5
File tree
3 files changed
+89
-4
lines changed- .changeset
- pkg/googlesheets
3 files changed
+89
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
250 | | - | |
251 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
252 | 278 | | |
253 | | - | |
254 | 279 | | |
255 | 280 | | |
256 | 281 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
0 commit comments