summaryrefslogtreecommitdiffstats
path: root/src/recur.c
Commit message (Collapse)AuthorAgeFilesLines
* Use time_t for system time valuesLukas Fleischer2019-01-141-20/+20
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix next recurring appointmentLars Henriksen2019-01-111-23/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Recurring appointments do not show up in the notification bar as next appointment. This was partly corrected by 2084f35 (Fix notification of recurrent appointments, 2017-02-09) and 5aa7a09 (Fix another error in the notification code, 2017-02-11). The search function recur_apoint_starts_before() had a wrong second argument, but is really of no use: the start time of a recurring appointment is the start time of the very first occurrence (in the past). A comparison against the item in the notify_app structure tells nothing of the start time of the current day; at most it eliminates some future recurring appointments. The function can be dropped, and the entire recurring appointment list looked through. The proper start time is found in the main search loop (and called real_recur_start_time) and must be compared against the item in the notify_app structure. But because recur_apoint_find_occurrence() is limited to a particular day (second argument), two searches are necessary to cover 24 hours. Unrelated cleanups: removed function return value; changed long to time_t. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Filter option: invertLars Henriksen2019-01-071-48/+53
| | | | | | | | | | | | | New filter option: --filter-invert. When present it inverts (negates) the other filter options combined. This is mostly useful with the -G option (with -Q the output is limited by the query range (day range)). The ouput from "calcurse -G <filter options>" is the (set) complement of "calcurse -G <filter options> --filter-invert". Here <filter options> may be any combination of filter options. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* CLI: filter options have no effect for dates before the epochLars Henriksen2019-01-071-8/+8
| | | | | | | | | | | | | | | | With the exception of filter.type_mask, a filter is only applied if set explicitly on the command line with a filter option. Whether that is the case, is determined by comparison with the initialization value. For date related filters (start_from/to, end_from/to) that is -1, hence the criterion is != -1, not >= 0. In generel, a filter initialization value should be invalid (i.e. one that cannot be set explicitly). As times before the epoch (1 January 1970 00:00:00 UTC) are negative, -1 is a valid Unix time. However, as it cannot be set from the command line, it is probably no problem? Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* DST fix: adjusting time in appointmentsLars Henriksen2018-11-101-5/+10
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Fix another error in the notification codeLukas Fleischer2017-02-111-1/+6
| | | | | | | | | | In addition to checking whether a recurrent item predates the current next appointment, we need to check that the actual occurrence of the item predates the current appointment as well. Fixes GitHub issue #26. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix notification of recurrent appointmentsLukas Fleischer2017-02-091-2/+8
| | | | | | | | | | | | | | | The recur_apoint_starts_before() filter function expected the second parameter to be passed by value, whereas its only caller passed the value by reference. For consistency with apoint_starts_after(), change the signature and the implementation of recur_apoint_starts_before() such that the parameter is passed by reference. Also, add a comment to the only caller of recur_apoint_starts_before() to clarify on why recur_apoint_starts_before() is used. Fixes GitHub issue #25. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright rangesLukas Fleischer2017-01-121-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Do not assume that days always have 86400 secondsLukas Fleischer2016-03-271-2/+2
| | | | | | | | 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>
* Improve ordering of appointments/eventsLukas Fleischer2016-02-151-9/+22
| | | | | | | | * Order by start time first. * Order items with the same start time by priority. * Order items with the same start and priority by description. 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 an option to filter by object hashLukas Fleischer2016-01-131-3/+29
| | | | | | | | | 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-0/+21
| | | | | | | Add new format specifiers to print the raw item representation or an object's hash value. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Implement recur_{apoint,event}_tostr()Lukas Fleischer2016-01-131-27/+51
| | | | | | | Add functions to serialize recurrent items without immediately writing them to stdout. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add support for --filter-end-* to eventsLukas Fleischer2015-05-201-1/+6
| | | | | | | A natural convention is to specify the end time of an event as 23:59:59 on the day it is scheduled. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Use time_t instead of long in several placesLukas Fleischer2015-02-241-4/+4
| | | | | | | Start converting some variables and return values to store times from long to time_t. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Update copyright rangesLukas Fleischer2015-02-071-1/+1
| | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add pattern filter optionLukas Fleischer2014-08-061-0/+4
| | | | | | | This adds a new item filter option --filter-pattern and removes the whole -S parameter logic, while making -S an alias for --filter-pattern. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add item filtersLukas Fleischer2014-08-061-2/+28
| | | | | | | | | | | | | | | | | This adds the following filter options that allow for restricting the set of items that are read from the appointments file: * --filter-type * --filter-start-from * --filter-start-to * --filter-start-after * --filter-start-before * --filter-end-from * --filter-end-to * --filter-end-after * --filter-end-before Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Initialize linked list for recurrent itemsLukas Fleischer2014-07-161-0/+5
| | | | | | | | | | When switching to the generic linked list implementation for recurring events in 9fab248 (Use generic lists for recurring apointments and events., 2011-04-16), no initialization routine for the list of recurring events was added. Fix this and properly initialize the list on startup. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* recur.c: Refactor/Reformat recur_item_find_occurrence()Lukas Fleischer2013-05-021-17/+13
| | | | | | | Fix a couple of whitespace and line breaks. Bail out early instead of using nested if statements. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* recur_exc_scan(): Do not check time of exceptionsLukas Fleischer2013-04-141-2/+1
| | | | | | | | | | Exceptions do not contain a time field -- do not check time fields which may be uninitialized. Regression introduced in 9907069f442c56c90b67accb2d8fbd046dfce6db. This fixes test/recur-*.sh. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use tabs instead of spaces for indentationLukas Fleischer2013-04-141-543/+562
| | | | | | | | | | | This completes our switch to the Linux kernel coding style. Note that we still use deeply nested constructs at some places which need to be fixed up later. Converted using the `Lindent` script from the Linux kernel code base, along with some manual fixes. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Validate date/time when scanning itemsLukas Fleischer2013-02-271-0/+19
| | | | | | | | | | | | | | | | Bail out when reading dates such as "02/30/2013" from the appointments file. These *could* be converted into valid dates but since we never write invalid dates to that file, these indicate a user error. Fixes following test cases: * appointment-009.sh * appointment-012.sh * appointment-016.sh * appointment-019.sh * event-003.sh Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Fix braces in if-else statementsLukas Fleischer2013-02-171-3/+6
| | | | | | | | | | From the Linux kernel coding guidelines: Do not unnecessarily use braces where a single statement will do. [...] This does not apply if one branch of a conditional statement is a single statement. Use braces in both branches. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Update copyright rangesLukas Fleischer2013-02-041-1/+1
| | | | | | | Add 2013 to the copyright range for all source and documentation files. Reported-by: Frederic Culot <frederic@culot.org> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Merge branch 'maint'Lukas Fleischer2012-11-231-27/+27
|\ | | | | | | | | | | Conflicts: src/day.c src/recur.c
| * Replace localtime() with localtime_r()Lukas Fleischer2012-11-221-30/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Since the result of localtime() is stored in a statically allocated structure, data was overwritten when a context switch occurred during (or shortly after) the execution of localtime(), potentially resulting in critical data corruption. BUG#7 and BUG#8 are likely related. This patch converts all usages of localtime() with localtime_r(), which is thread-safe. Reported-by: Baptiste Jonglez <baptiste@jonglez.org> Reported-by: Erik Saule <esaule@bmi.osu.edu> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Remove the erase flag and legacy deletion codeLukas Fleischer2012-07-071-35/+9
| | | | | | | | | | | | | | | | This is no longer needed. Note removal, as well as exception handling, have been moved to separate functions and the cut feature has been merged into the deletion function. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Refactor exception handlingLukas Fleischer2012-07-071-40/+49
| | | | | | | | | | | | | | | | | | Remove the exception handling code from recur_*_erase() and move it to separate functions recur_*_add_exc(). Create a wrapper function day_item_add_exc() that can be used to add an exception to generic items. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Refactor note removalLukas Fleischer2012-07-071-7/+1
| | | | | | | | | | | | | | | | Remove the note removal code from *_delete()/*_erase() and create a new wrapper function called day_item_erase_note() that is be used to drop the note being associated to an item. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Refactor *_dup()Lukas Fleischer2012-07-061-23/+35
| | | | | | | | | | | | | | | | * Actually duplicate an item instead of copying data only. * Properly clone an item without a note. * Mark *_dup() public. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Remove legacy cut/paste codeLukas Fleischer2012-06-301-30/+0
| | | | | | | | | | | | | | Note that this doesn't remove *_dup() since these might still be needed later. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Revise cut/pastingLukas Fleischer2012-06-301-40/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of calling type-specific duplication handlers and inserting clones of the original items when pasting, save the generic day item and remove the actual item from the linked list, so that it can be inserted anywhere else later. The cut/paste buffer is moved to the interaction unit, item-specific cut operations are changed to remove the item from the linked list only instead of copying and freeing it. An item is only freed if another item is cut before the current cut/paste buffer is pasted. All paste operations are changed and reinsert the actual item instead of creating a clone. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Make *_free() publicLukas Fleischer2012-06-301-2/+2
| | | | | | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Revise *_delete{,_bynum}()Lukas Fleischer2012-06-301-11/+5
| | | | | | | | | | | | | | | | Always pass an item instead of passing a date and a index. This makes use of the NULL callback that was added with one of the previous patches. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Allow passing more complex data to list callbacksLukas Fleischer2012-06-301-10/+10
| | | | | | | | | | | | | | | | Change the data type of the "data" parameter from "long" to "void *" in llist_find_*() signatures to allow for passing more complex objects. Change all llist_find_*() invocations and callbacks accordingly. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Move interaction functions to a separate fileLukas Fleischer2012-06-301-136/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a first step to clean up several compilation units and separate the front end from back-end operations. All functions that require user interaction are moved to a new compilation unit "interaction.c". Also, following things are adjusted to the new layout: * Make day_item_get_*() and a few other functions public, so that it can be accessed from the new compilation unit. * Use apoint_hilt(), todo_hilt(), etc. instead of directly accessing static variables. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Remove unused functionsLukas Fleischer2012-06-301-26/+0
| | | | | | | | | | | | | | Remove apoint_get(), event_get(), recur_get_apoint() and recur_get_event(), since they are no longer used. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Simplify recur_apoint_switch_notify()Lukas Fleischer2012-06-301-9/+1
| | | | | | | | | | | | | | | | | | Pass the recurrent appointment itself instead of passing a date and an item number. This is quite simple as we can just pass the pointer that is contained in the generic item structure and don't have to LLIST_TS_FIND_*() the item first any more. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Rework generic item containerLukas Fleischer2012-06-301-4/+6
|/ | | | | | | | | Instead of copying all members of the individual item structures to a generic structure containing all fields, create compulsory fields only and set up a pointer to the actual item. This results in lower memory footprint and lets us clean up some code. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Fix incorrect i18n usage for some stringsBaptiste Jonglez2012-05-251-2/+2
| | | | | | | | | | | Some strings are initialized without wrapping them in _(); instead, _() is applied on the variable when it is used. This is incorrect, since these strings don't get added to the catalog. Fix that by applying _() only once, when the string is declared. Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Switch to Linux kernel coding styleLukas Fleischer2012-05-211-664/+549
| | | | | | | | | | | | | | Convert our code base to adhere to Linux kernel coding style using Lindent, with the following exceptions: * Use spaces, instead of tabs, for indentation. * Use 2-character indentations (instead of 8 characters). Rationale: We currently have too much levels of indentation. Using 8-character tabs would make huge code parts unreadable. These need to be cleaned up before we can switch to 8 characters. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use status_ask_choice() on more difficult casesBaptiste Jonglez2012-05-141-16/+29
| | | | | | | | | | | These cases are also candidates for the factorisation process, but they are somewhat more tricky to get right. Since we use a completely different approach, the result (from a user perspective) looks different. Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Miscellaneous small code cleanupsLukas Fleischer2012-04-061-1/+1
| | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Mark localized string literals constantLukas Fleischer2012-04-051-10/+10
| | | | | | | Translated strings returned by gettext() are statically allocated and shouldn't be modified. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Update copyright rangesLukas Fleischer2012-03-261-1/+1
| | | | | | Add 2012 to the copyright range for all source and documentation files. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use strcmp() instead of strncmp()Lukas Fleischer2012-03-121-1/+1
| | | | | | | | | strncmp() isn't intended to be a secure strcmp() replacement, it is designed to be used if you want to compare the first n characters of two strings. Since we always compare character pointers with string literals, switch to using strcmp() everywhere. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Fix up fscanf() format stringsLukas Fleischer2012-02-191-1/+1
| | | | | | | All members of the tm structure are signed integers. Stick to using the correct fscanf() format specifiers for these. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Trap fgets() failure in *_scan()Lukas Fleischer2012-02-181-2/+6
| | | | | | | | Ensure we don't read arbitrary data when fgets() returns a NULL string (meaning that either the EOF is encountered or an error occurred). This also fixes a couple of compiler warnings seen with "-Wunused-result". Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>