You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: R/utils.R
+39-1Lines changed: 39 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,45 @@ has_star <- function(x) {
57
57
#' `format(as.POSIXct(x, tz=""), format="%Y-%m-%d")` to get a string with format
58
58
#' YYYY-MM-DD.
59
59
#'
60
-
# TODO: check the previous statements
60
+
# TODO: check the previous and following statements
61
+
#
62
+
# ACCORDING TO Copilot:
63
+
# ### **Analysis**:
64
+
# 1. **Excel Date Storage**:
65
+
# - Excel does **not** store dates as the number of days since January 1, 1970. Instead:
66
+
# - Excel stores dates as the number of days since **January 1, 1900** (for Windows systems) or **January 1, 1904** (for macOS systems).
67
+
# - Excel also incorrectly assumes that 1900 was a leap year, which introduces an offset of 1 day for dates before March 1, 1900.
68
+
#
69
+
# 2. **`read_excel` Behavior**:
70
+
# - When using `readxl::read_excel`, Excel dates are typically read as numeric values representing the number of days since Excel's epoch (e.g., 1900 or 1904). These values are **not automatically converted to POSIXct** by `read_excel`. The user must manually convert them.
71
+
#
72
+
# 3. **POSIXct Conversion**:
73
+
# - The description mentions converting the number to a date using `as.POSIXct(as.integer(x))`. However:
74
+
# - This assumes that the numeric value `x` is already in seconds since January 1, 1970, which is not the case for Excel dates.
75
+
# - To convert Excel dates to R's `POSIXct`, you need to account for Excel's epoch (e.g., subtract the appropriate offset for 1900 or 1904).
76
+
#
77
+
# 4. **Formatting**:
78
+
# - The description correctly states that `format(as.POSIXct(x, tz=""), format="%Y-%m-%d")` can be used to format a `POSIXct` object as a string in the `YYYY-MM-DD` format.
79
+
#
80
+
# ### **Corrected Description**:
81
+
# Here’s a revised and accurate version of the description:
82
+
#
83
+
# Excel stores dates as numeric values representing the number of days since
84
+
# January 1, 1900 (Windows) or January 1, 1904 (macOS). Note that Excel's 1900
85
+
# date system incorrectly assumes 1900 was a leap year, which introduces a
86
+
# 1-day offset for dates before March 1, 1900.
87
+
#
88
+
# When read using `readxl::read_excel`, Excel dates are imported as numeric
89
+
# values. To convert these to R's `POSIXct` class, you must account for Excel's
90
+
# epoch. For example, subtract 25569 days (the number of days between January 1,
91
+
# 1900, and January 1, 1970) and convert to seconds by multiplying by 86400.
0 commit comments