summaryrefslogtreecommitdiff
path: root/Libraries/LibC
diff options
context:
space:
mode:
authorhowar6hill <f.eiwu@yahoo.com>2020-03-08 19:50:56 +0800
committerAndreas Kling <kling@serenityos.org>2020-03-08 13:56:01 +0100
commite72fb8f594484db58714eadbf5d10b735e3f5851 (patch)
tree22be9bc2ff0996b7e299f94c5a1278d11aacfdb4 /Libraries/LibC
parentdf40847c523c718990c4e20714057654cdad319b (diff)
downloadserenity-e72fb8f594484db58714eadbf5d10b735e3f5851.zip
LibC: Fix a bug involving miscalculating week counts of last year
Diffstat (limited to 'Libraries/LibC')
-rw-r--r--Libraries/LibC/time.cpp37
1 files changed, 17 insertions, 20 deletions
diff --git a/Libraries/LibC/time.cpp b/Libraries/LibC/time.cpp
index 0c011f5176..acf90f54af 100644
--- a/Libraries/LibC/time.cpp
+++ b/Libraries/LibC/time.cpp
@@ -148,24 +148,6 @@ struct tm* gmtime_r(const time_t* t, struct tm* tm)
return tm;
}
-static char wday_short_names[7][4] = {
- "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
-};
-
-static char wday_long_names[7][10] = {
- "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
-};
-
-static char mon_short_names[12][4] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-
-static char mon_long_names[12][10] = {
- "January", "February", "March", "April", "May", "June",
- "July", "Auguest", "September", "October", "November", "December"
-};
-
char* asctime(const struct tm* tm)
{
static char buffer[69];
@@ -176,6 +158,21 @@ char* asctime(const struct tm* tm)
//FIXME: Some formats are not supported.
size_t strftime(char* destination, size_t max_size, const char* format, const struct tm* tm)
{
+ const char wday_short_names[7][4] = {
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+ };
+ const char wday_long_names[7][10] = {
+ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
+ };
+ const char mon_short_names[12][4] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+ };
+ const char mon_long_names[12][10] = {
+ "January", "February", "March", "April", "May", "June",
+ "July", "Auguest", "September", "October", "November", "December"
+ };
+
StringBuilder builder { max_size - 1 };
const int format_len = strlen(format);
@@ -266,10 +263,10 @@ size_t strftime(char* destination, size_t max_size, const char* format, const st
if (tm->tm_yday >= 7 - wday_of_year_beginning)
--week_number;
else {
- const int days_of_last_year = 365 + __is_leap_year(tm->tm_year + 1900);
+ const int days_of_last_year = 365 + __is_leap_year(tm->tm_year + 1900 - 1);
const int wday_of_last_year_beginning = (wday_of_year_beginning + 6 * days_of_last_year) % 7;
week_number = (days_of_last_year + wday_of_last_year_beginning) / 7 + 1;
- if (wday_of_year_beginning > 3)
+ if (wday_of_last_year_beginning > 3)
--week_number;
}
}