aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.c
Commit message (Collapse)AuthorAgeFilesLines
* DST: fix date_change() thoroughlyLars Henriksen2019-09-061-1/+2
| | | | | | | | Explicit setting of Daylight Saving Time should be avoided before as well as after the mktime() call. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Use empty end date instead of 0 when editing repetitionsLukas Fleischer2019-06-061-16/+8
| | | | | | | | | Since commit 987fa9d (Allow to omit end date in repetitions, 2019-06-03), one can provide an empty date instead of using the value 0 to omit the end date of a repetition. Use this as default value when editing repetitions without an end date. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Remove appointments panel scrollbar in multiple days modeLars Henriksen2019-05-281-0/+4
| | | | | | | | | | A scrollbar gives the impression of a fixed list. But the list on display is automatically and silently changed as needed for movements in the panel or the calendar, thus creating the illusion of an endless list. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Derive selected day from selected itemLars Henriksen2019-05-221-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, with only one day visible at a time, the appointments panel displayed the details of the day selected in the calendar (slctd_day); information required for operations on items (day_items) can often be derived from the selected day. The items available are derived from the selected day. In particular, the selected item is derived from the selected day. With multiple days in the APP panel, the relation between selected day (in the calendar) and the selected item (in the APP panel) has, in a way, been turned around. The selected item may now be moved between days without explicitly changing the selected day. Implicitly it is changed when the target day of a move is unavailable. This commit draws the full consequence: the selected day in the calendar is always (set to) the day of the selected item in the APP panel. The static variable 'struct date slctd_day' lives in ui_calendar.c and is accessible through various public functions. To these are added ui_calendar_set_slctd_day() which sets slctd_day directly. The selected day retains its significance for load of the day vector (in day_store_items()): the range of loaded days begins with the selected day. Movements (up/down) in the APP panel will change the selected day as the selected item moves among the already loaded days. Only when the target of a movement is unreachable, will further days be loaded. On the other hand, if the same range of days must be reloaded because of a changed item, the selected item - and with it the selected day - must be reset to the first day item (see do_storage()). Movements in the calendar (generic-next-day, etc.) are not affected and behave as previously, i.e. they will cause a range of days to be loaded with the selected day as the first and the selected item as the first of the selected day. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add week numbers in the calendar and full first and last weekLars Henriksen2019-05-221-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | Much in the calendar is based on the selected day, struct date slctd_day, in ui-calendar.c. On the screen it is highlighted with a deviating colour. The highlight effect has been changed to a pair of red square brackets that do not obscure the day colour. The week number (in the frame) used to be that of the selected day, but has no obvious relation to the days in the APP panel. It has been replaced by the year day number of the selected day. The week numbers of all visible weeks are displayed to the left of the calendar. Dates are displayed also for the overlapping parts of the first and last week of the month (which do not belong to the month). Days are accessible in the appointments panel as well as in the calendar. Hence, validation of days (= inside UNIX time limits) must be extended from the calendar (in ui_calendar_move()) to include loaded days (in day_store_items()). Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Simplify day storageLars Henriksen2019-05-221-0/+6
| | | | | | | | | | | The function day_process_storage() is a wrapper for day_store_items(). It has an unused second argument, and is only used twice to load the selected day. It has been removed. A new function, get_slctd_day(), is the equivalant of get_today() and replaces the very awkwardly named ui_calendar_get_slctd_day_sec(). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Overflow check for 32-bit types onlyLars Henriksen2019-01-181-10/+16
| | | | | | | Included is a check of the 'until' date for pasted recurrent items. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Use time_t for system time valuesLukas Fleischer2019-01-141-20/+20
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix print_date()Lars Henriksen2019-01-071-5/+8
| | | | | | | | In print_date(date, day, ...) it is silently assumed that day is midnight (beginning) of the day to be printed. Assume only that it belongs to the day. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* DST fix: adjusting time in appointmentsLars Henriksen2018-11-101-5/+23
| | | | | | | | | | | | | | | | | | | | | | | | | Calcurse saves time and date information on disk as local time in readable text file format. When loaded from disk or when entered by the user, local time is converted to Unix time (seconds since 00:00:00, 1 January 1970). When displayed, and later when saved to disk, the Unix time is converted back to readable local time. Both conversions depend on DST. Hence, if midnight for a day with DST in effect (i.e. local time) is converted, increased with an amount and converted back, the amount has changed if DST is _not_ in effect for the resulting time. In general, calculations on Unix time variables should be used with caution because of the DST-dependent conversions. Instead, the calculations should be performed on local time data with the help of mktime(). The commit fixes start time for pasted appointments (ordinary and recurrent) and the 'until'-date of recurrent appointments, pasted as well as new and edited. The latter problem is slightly different in that the adjustment is a number of days, as it is for exception dates. Update of the date in parse_datetime() has been corrected to be similar to update of the time, although no problem has been identified. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* DST fix: adding appointments on the day when DST starts or stopsLars Henriksen2018-11-101-11/+7
| | | | | | | | | | A new apppoint inserted on the day when the clock is adjusted backward by an hour got a wrong start time (an hour late). Reason: mktime() must not use the Daylight Saving Time information returned by localtime_r(). Also editorial simplifications. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Minor merge adjustmentsLars Henriksen2018-08-251-36/+43
| | | | | | | | Comments inserted. Slightly different implementations of parse_time() and parse_datetime(). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Start and end time validation.Lars Henriksen2018-08-251-5/+44
| | | | | | | | | | All appointment times are checked for validity. Overflow by time arithmetic is detected. End times are checked when appointments are moved. Three functions are involved: parse_datetime(), parse_duration() and parse_date_duration(); they all have a new argument for validation purposes. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* New support functions for input validation.Lars Henriksen2018-08-251-0/+36
| | | | | | check_sec(), overflow_add(), overflow_mul() Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Only stop threads when exiting from interactive modeLukas Fleischer2018-08-251-3/+3
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Support UTF-8 encoded characters in user choicesLars Henriksen2018-06-031-12/+23
| | | | | | | | Translations (in po-files) of texts that are used for alternative choices (e.g. [dwmy]), may use UTF-8 encoded Unicode characters (e.g. [éãüå]). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Scrollbar and right window border (corrected)Lars Henriksen2018-05-261-15/+8
| | | | | | | | | | | | | | | | | When a scrollbar is on display in APP or TOD windows, the right vertical border (outside the scrollbar) is not highlighted when the window is selected. The scrollbar is always highlighted: - when APP or TOD is deselected - in configuration windows where borders otherwise are not The patch moves the scrollbar parameters (except highlight) from arguments of draw_scrollbar() to the function itself. The highlight argument was 1; instead it is set higher in the call hierarchy (wins_update_panels()) and passed on down. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Scrollbar and right window borderLars Henriksen2017-12-101-8/+27
| | | | | | | | | | | | | | | | | | | When a scrollbar is on display in APP or TOD windows, the right vertical border (outside the scrollbar) is not highlighted when the window is selected. The scrollbar itself is always highlighted: - when APP or TOD is deselected - in configuration windows where borders otherwise are not The patch moves the scrollbar parameters from arguments of draw_scrollbar() to the function itself. The highlight argument to draw_scrollbar() was always 1. Instead call circumstances are figured out and highlight set accordingly. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Default colour as foreground colourLars Henriksen2017-12-101-0/+6
| | | | | | | | | | | | | In the default colour setup (white on black), white could only with great difficulty be used as customized foreground colour, because the colour pair COLR_CUSTOM then was identical to COLR_DEFAULT (default on default). This made it impossible to distinguish the selected element in lists. The patch turns on the video attribute bold when default is chosen as foreground colour. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Check for the year span 1902-2037Lars Henriksen2017-11-231-6/+8
| | | | | | | | | | | | | Reintroduce year check for systems with a 32-bit time_t type. Remove the lower limit (1902) for systems with a 64-bit time_t. This limits movements in the calendar (for 32-bit systems) and in no way ensures constistency of data. Commit a12833e (Handle dates past January 19th, 2038, 2015-01-19) removed the upper limit (2037) on dates but left the lower limit (1902). It did not ensure the support of the target system. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Parse time before date in parse_datetime()Lukas Fleischer2017-10-271-2/+2
| | | | | | | | | Make sure that in cases when the date and time formats conflict, such as is the case with "0030", the input is interpreted as a time value, not a date. Suggested-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Make parsing of date-time more strictLukas Fleischer2017-10-261-15/+20
| | | | | | | | | | | In parse_datetime() it was possible to enter any number of dates and times in any order. Allow just date or time or date followed by time. Time must be looked for before date because of conflicting time and date formats. Suggested-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add parse_date_interactive()Lukas Fleischer2017-10-261-0/+7
| | | | | | | | | Add a wrapper around parse_date() which picks the current input date format as well as the currently selected day and passes both values to parse_date(), alongside with the parameters passed to parse_date_interactive() itself. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Remove phase of moon featureLars Henriksen2017-09-081-2/+0
| | | | | | | | | | The computation never really worked before and it seems like the feature is not very helpful, sometimes even confusing (see GitHub issue #21). The macro ISLEAP is moved to calcurse.h. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Replace remaining uses of wgetch() by keys_wgetch()Lukas Fleischer2017-09-031-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add a function to wait for any key pressLukas Fleischer2017-09-031-3/+3
| | | | | | | Introduce a new function keys_wait_for_any_key() and use it instead of wgetch() whenever the return value is discarded. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix empty warning box when key is already in useLars Henriksen2017-08-121-0/+2
| | | | | | | | | | | | When adding a key already in use for another action, a warning box is displayed. The text length is limited by the window width through the use of strncpy(). If the limit is exceeded, the string will have no null termination, resulting in unpredictable behaviour. A similar problem in fatalbox() is fixed as well. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Include stdarg.h when using variable argument listsLukas Fleischer2017-07-281-0/+1
| | | | | | Fixes GitHub issue #36. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright rangesLukas Fleischer2017-01-121-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Replace parse_datetime() constants by named flagsLukas Fleischer2016-10-101-2/+2
| | | | | | | Remove the magic constants used in the return value of parse_datetime() and use named flags instead. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Support dates when specifying start/end timesLukas Fleischer2016-10-091-2/+6
| | | | | | | | | | Add support for combined date/time or date-only strings when specifying the start or end time of a new item. This is a follow-up to 1f39b5c (Add support for moving items to another day, 2016-09-30). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Factor out parse_datetime()Lukas Fleischer2016-10-091-0/+39
| | | | | | | | Create a new function that takes a time stamp and updates the date or time components of that time stamp according to a given date/time string. Use that function for updating the start time of an item. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Stop all threads before leaving curses modeLukas Fleischer2016-09-131-2/+4
| | | | | | | This prevents from notification bar artifacts being drawn after leaving interactive mode. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Do not assume that days always have 86400 secondsLukas Fleischer2016-03-271-0/+24
| | | | | | | | Make that date membership is computed correctly, even if a day has less than 86400 seconds (e.g. after changing clocks). Reported-by: Hakan Jerning <jerning@home.se> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Support durations in recurrence ending datesLukas Fleischer2016-02-261-0/+91
| | | | | | | When spending the end date of recurring items, allow date duration specifiers such as "+5d" or "+3w2d". Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Allow decimals in durationsLukas Fleischer2016-02-101-9/+16
| | | | | | Parse durations containing decimal numbers (such as "1.5h") gracefully. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix %(hash) formatting of eventsLukas Fleischer2016-02-051-2/+2
| | | | | | Actually print the hash instead of raw object data. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Refactor grep modeLukas Fleischer2016-02-051-0/+1
| | | | | | | | | Split io_save_{apts,todo}() into functions that write raw data to a file and functions that write formatted items to stdout such that one can easily extend the grep mode for format string support in a follow-up commit. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright rangesLukas Fleischer2016-01-301-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add command line option to suppress dialogsLukas Fleischer2016-01-131-0/+5
| | | | | | | Implement a -q/--quiet command line option to disable system dialogs temporarily. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add an option to filter by object hashLukas Fleischer2016-01-131-0/+12
| | | | | | | | | Implement a new --filter-hash option to filter by object identifiers. Each object having an identifier that has the specified pattern as a prefix is matched. Patterns starting with an exclamation mark (!) are interpreted as negative patterns. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add long format specifiers "raw" and "hash"Lukas Fleischer2016-01-131-5/+55
| | | | | | | Add new format specifiers to print the raw item representation or an object's hash value. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Reimplement asprintf() using dynamic stringsLukas Fleischer2016-01-131-26/+4
| | | | | | Use the new string implementation to simplify asprintf(). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Split out code for drawing week numbersLukas Fleischer2015-04-101-2/+9
| | | | | | | This allows for easily adding week numbers to other panel modes, such as the monthly view. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Simplify code in status_ask_choice()Lukas Fleischer2015-02-241-7/+5
| | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use time_t instead of long in several placesLukas Fleischer2015-02-241-16/+10
| | | | | | | Start converting some variables and return values to store times from long to time_t. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Introduce starts_with() and starts_with_ci()Lukas Fleischer2015-02-241-0/+12
| | | | | | | | Create user-defined functions to check whether a string contains a certain prefix instead of messing around with strncmp() and strncasecmp(). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add support for UTC times in iCal importsLukas Fleischer2015-02-231-0/+25
| | | | | | | | | | | | | | According to the iCal standard (4.3.12 Time): UTC time, or absolute time, is identified by a LATIN CAPITAL LETTER Z suffix character (US-ASCII decimal 90), the UTC designator, appended to the time value. Parse such time values properly when importing iCal files. Fixes GitHub issue #3. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use date_sec_change() for adding day deltasLukas Fleischer2015-02-221-6/+5
| | | | | | Fixes tests range-002.sh and search-001.sh. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Support weekday names as date specifiersLukas Fleischer2015-02-111-5/+51
| | | | | | Allow for using shorthands like "Monday" as date specifiers. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>