elementary / elementary/panel-datetime

Model `week_starts_on` doesn't handle Sunday

Open
#224 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Vala
Stars
31
Forks
18
Avg merge
2h 29m
Merged PRs (30d)
2

Description

## Prerequisites
- [x] I have searched open and closed issues for duplicates.

## Describe the bug
In `CalendarModel.vala`, the first day of the week is set from `Posix.NLTime.FIRST_WEEKDAY`. The way that it's implemented doesn't work with weeks that start on Sunday (for example, in the US). From what I can tell (I can't find docs on `FIRST_WEKDAY` or `nl_langinfo(_NL_TIME_FIRST_WEEKDAY)`, which I think is what this actually calls), `langinfo` uses Sunday = 1 through Saturday = 7. GLib uses Monday = 1 through Sunday = 7. So the method to subtract 1 from the `Posix` call works when the weekday is Monday or later, but Sunday will become 0. This is the enum value of `BAD_WEEKDAY`. Instead, it should wrap around to 7.

GNOME Calendar uses another call to `WEEK_DAY1` to do this "wrap around" behavior. I've tried to implement this in Vala, but I can't get that value without a segfault, so I'm not sure how to fix this. FWIW, here's their code:
```c
union { unsigned int word; char *string; } langinfo;
gint week_1stday = 0;
gint first_weekday = 1;
guint week_origin;

langinfo.string = nl_langinfo (_NL_TIME_FIRST_WEEKDAY);
first_weekday = langinfo.string[0];
langinfo.string = nl_langinfo (_NL_TIME_WEEK_1STDAY);
week_origin = langinfo.word;
if (week_origin == 19971130) /* Sunday */
week_1stday = 0;
else if (week_origin == 19971201) /* Monday */
week_1stday = 1;
else
g_warning ("Unknown value of _NL_TIME_WEEK_1STDAY.\n");

week_start = (week_1stday + first_weekday - 1) % 7;
```

## Platform Information

- [x] I'm using the latest version from git that I've manually compiled
- [ ] I'm using the latest released stable version

![about](https://user-images.githubusercontent.com/29022469/84616875-73d0b900-ae8a-11ea-8f7e-671b3f2d69e3.png)

---
Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/92529701-model-week_starts_on-doesn-t-handle-sunday?utm_campaign=plugin&utm_content=tracker%2F57456330&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F57456330&utm_medium=issues&utm_source=github).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.