commit 2ecf809f92c75da07671f6f0417c7ec2b9a5e7c6
parent 45fc1985167609ee39e32f36fa55a77cc8fe12c5
Author: Andreas Gruhler <agruhl@gmx.ch>
Date: Sun, 17 Jan 2021 13:16:49 +0100
Change first_weekday to weekday
The long option 'weekday' maps much better to the short option '-w'.
Diffstat:
5 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md
@@ -85,5 +85,5 @@ The file `~/.config/diary/diary.cfg` should adhere to a basic `key = value` form
| --- | --- | --- | --- | --- |
| `--dir`, `-d`, or first non-option argument | `dir` | ~/diary | n/a | Diary directory. Path that holds the journal text files. |
| `--range` or `-r` | `range` | 10 | 1 | Number of years to show before/after todays date |
-| `--first_weekday` or `-w` | `first_weekday` | 0 | 1 | First weekday, `0` = Sunday, `1` = Monday, ..., `6` = Saturday. Use `0` to display week beginning at Sunday ("S-M-T-W-T-F-S"), or `1` for "M-T-W-T-F-S-S" (default) |
+| `--weekday` or `-w` | `weekday` | 0 | 1 | First weekday, `0` = Sunday, `1` = Monday, ..., `6` = Saturday. Use `0` to display week beginning at Sunday ("S-M-T-W-T-F-S"), or `1` for "M-T-W-T-F-S-S" (default) |
| `--date_fmt` or `-f` | `date_fmt` | %d_%b_%y | %Y-%m-%d | Date format and file name for the files inside the `dir`. For the format specifiers, see [`man strftime`](https://man7.org/linux/man-pages/man3/strftime.3.html). Be careful: If you change this, you might no longer find your existing diary entries, because the diary assumes to find the journal files under another file name. Hence, a change in FMT shows an empty diary, at first. Rename all files in the DIARY_DIR to migrate to a new FMT. |
\ No newline at end of file
diff --git a/diary.1 b/diary.1
@@ -81,7 +81,7 @@ Install an example config file with defaults:
# Number of years to show before/after todays date
range = 1
# 0 = Sunday, 1 = Monday, ..., 6 = Saturday
- first_weekday = 1
+ weekday = 1
# Date and file format, change with care
date_fmt = %Y-%m-%d' | sed 's/^[[:space:]]*//' > ~/.config/diary/diary.cfg
.fi
diff --git a/diary.c b/diary.c
@@ -24,11 +24,11 @@ void setup_cal_timeframe()
cal_start.tm_mday = 1;
mktime(&cal_start);
- if (cal_start.tm_wday != CONFIG.first_weekday) {
- // adjust start date to first_weekday before 01.01
+ if (cal_start.tm_wday != CONFIG.weekday) {
+ // adjust start date to weekday before 01.01
cal_start.tm_year--;
cal_start.tm_mon = 11;
- cal_start.tm_mday = 31 - (cal_start.tm_wday - CONFIG.first_weekday) + 1;
+ cal_start.tm_mday = 31 - (cal_start.tm_wday - CONFIG.weekday) + 1;
mktime(&cal_start);
}
@@ -42,7 +42,7 @@ void setup_cal_timeframe()
void draw_wdays(WINDOW* head)
{
int i;
- for (i = CONFIG.first_weekday; i < CONFIG.first_weekday + 7; i++) {
+ for (i = CONFIG.weekday; i < CONFIG.weekday + 7; i++) {
waddstr(head, WEEKDAYS[i % 7]);
waddch(head, ' ');
}
@@ -325,8 +325,8 @@ bool read_config(const char* file_path)
wordfree(&diary_dir_wordexp);
} else if (strcmp("range", key_buf) == 0) {
CONFIG.range = atoi(value_buf);
- } else if (strcmp("first_weekday", key_buf) == 0) {
- CONFIG.first_weekday = atoi(value_buf);
+ } else if (strcmp("weekday", key_buf) == 0) {
+ CONFIG.weekday = atoi(value_buf);
} else if (strcmp("date_fmt", key_buf) == 0) {
CONFIG.date_fmt = (char *) malloc(strlen(value_buf) + 1 * sizeof(char));
strcpy(CONFIG.date_fmt, value_buf);
@@ -348,7 +348,7 @@ void usage() {
printf(" -h, --help : Show diary help text\n");
printf(" -d, --dir DIARY_DIR : Diary storage directory DIARY_DIR\n");
printf(" -r, --range RANGE : RANGE is the number of years to show before/after today's date\n");
- printf(" -w, --first_weekday DAY : First day of the week, 0 = Sun, 1 = Mon, ..., 6 = Sat\n");
+ printf(" -w, --weekday DAY : First day of the week, 0 = Sun, 1 = Mon, ..., 6 = Sat\n");
printf(" -f, --date_fmt FMT : Date and file format, change with care\n");
printf("\n");
printf("Full docs and keyboard shortcuts: DIARY(1)\n");
@@ -381,15 +381,15 @@ int main(int argc, char** argv) {
.tm_year = d / (100 * 100) - 1900
};
mktime(&base);
- // first_weekday is base date's day of the week offset by (_NL_TIME_FIRST_WEEKDAY - 1)
+ // weekday is base date's day of the week offset by (_NL_TIME_FIRST_WEEKDAY - 1)
#ifdef __linux__
- CONFIG.first_weekday = (base.tm_wday + *nl_langinfo(_NL_TIME_FIRST_WEEKDAY) - 1) % 7;
+ CONFIG.weekday = (base.tm_wday + *nl_langinfo(_NL_TIME_FIRST_WEEKDAY) - 1) % 7;
#elif defined __MACH__
CFIndex first_day_of_week;
CFCalendarRef currentCalendar = CFCalendarCopyCurrent();
first_day_of_week = CFCalendarGetFirstWeekday(currentCalendar);
CFRelease(currentCalendar);
- CONFIG.first_weekday = (base.tm_wday + first_day_of_week - 1) % 7;
+ CONFIG.weekday = (base.tm_wday + first_day_of_week - 1) % 7;
#endif
#endif
@@ -426,7 +426,7 @@ int main(int argc, char** argv) {
{ "help", no_argument, 0, 'h' },
{ "dir", required_argument, 0, 'd' },
{ "range", required_argument, 0, 'r' },
- { "first_weekday", required_argument, 0, 'w' },
+ { "weekday", required_argument, 0, 'w' },
{ "date_fmt", required_argument, 0, 'f' },
{ 0, 0, 0, 0 }
};
@@ -463,7 +463,7 @@ int main(int argc, char** argv) {
case 'w':
// set first week day from option character
fprintf(stderr, "%i\n", atoi(optarg));
- CONFIG.first_weekday = atoi(optarg);
+ CONFIG.weekday = atoi(optarg);
break;
case 'f':
// set date format from option character
diff --git a/diary.cfg b/diary.cfg
@@ -3,6 +3,6 @@
# Number of years to show before/after todays date
range = 1
# 0 = Sunday, 1 = Monday, ..., 6 = Saturday
-first_weekday = 1
+weekday = 1
# Date and file format, change with care
date_fmt = %Y-%m-%d
diff --git a/diary.h b/diary.h
@@ -48,14 +48,14 @@ typedef struct
// Number of years to show before/after todays date
int range;
// 0 = Sunday, 1 = Monday, ..., 6 = Saturday
- int first_weekday;
+ int weekday;
// 2020-12-31
char* date_fmt;
} config;
config CONFIG = {
.range = 1,
- .first_weekday = 1,
+ .weekday = 1,
.date_fmt = "%Y-%m-%d"
};