Prev: Personal Data
Module agenda: Agenda Database
This module allows to read and manipulate the agenda (calendar and to-do list) stored on the phone. There are different types of agenda entries, each type identified by its flag:
- Appointment (agenda.appt flag): an entry starting at a date and time and ending on the same day, e.g. a team meeting.
- Event (agenda.event flag): an entry starting at a date and ending on a date, e.g. holidays.
- Anniversary (agenda.anniv flag): an entry occuring at a date, with an optional base year (e.g. the year of birth).
- To-do list item (agenda.todo flag): an entry with a due date and a priority. When done, it also gets a done ("crossed out") date.
The standard calendar application on the phone often does not support all entry types and attributes.
In the phone's database, an agenda entry is identified by its id, an integer number.
In m, an agenda entry is represented as an array whose elements are the fields of the entry. Fields are identified by their (array) keys. m recognizes the following keys, with the corresponding data type:
| Key||Meaning||Type||Used in|
| alarm||Alarm date/time||Seconds||•||•||•||•|
|flags||Entry flags (see below)||Number||•||•||•||•|
|rep||Repeat details (see below)||Array||•||•||•||•|
Key names are not case sensitive.
All dates and times of an entry are represented as seconds since the start of year zero in local time (see also module time). Valid dates are January 1st, 1980 or 1900 to December 31st, 2100. The functions of this module throw ExcValueOutOfRange if a date outside this range is used. The only exception is the base year (base) of an anniversary entry, which is simply an integer indicating any year.
The order of fields in the array describing an entry is arbitrary. Arrays returned by functions in this module always start with the two fields text and flags.
Agenda Entry Flags
field is a bitwise combination of the following values:
• const anniv = 4
Entry is an anniversary.
• const appt = 1
Entry is an appointment.
• const done = 32
To-do entry is done.
• const event = 2
Entry is an event.
• const rep = 16
Entry is repeated.
• const remind = 64
Entry is a reminder.
• const todo = 8
Entry is a to-do list item.
Flags can be used to select entries in agenda.find, and they must be used to indicate the type of the new entry in agenda.add.
For use in agenda.find, there is also the value
• const all = 127
All flags combined.
field defines how an entry is handled during synchronisation:
• const public = 0
Synchronise and make entry visible if the calendar is online.
• const private = 1
Hide entry from viewers if the calendar is available online.
• const none = 2
Entry will not be copied to computer.
All dated entries can be repetitive: a repetitive entry is automatically repeated according to its repeat details. For instance, an anniversary is typically repeated on the same date every year. Repeating an entry does not duplicate the entry; deleting or updating a repetitive entry also deletes or updates all its repetitions.
In m, the repeat details of an entry are represented as an array stored in the entry's rep field. m recognizes the following keys of this array, with the corresponding data type:
| Key||Meaning||Type |
| end||Repeat end date||Seconds |
|interval||Repeat interval (days, months, years)||Number |
|type||Repeat type (see below)||Number |
|when||Repeat selection (see below)||Array of Number |
If end=null (the default), the entry is repeated forever. The default interval is 1. type must be one of the following six values:
• const daily = Repeat daily.
Repeat the entry every interval days.
// plan for an 30 minute exercise at 8am|
// every three days, starting today
today=86400 * math.trunc(time.get() / 86400);
• const weekly = Repeat weekly.
Repeat the entry every interval weeks, on the week days indicated by when. Week days start with zero as Monday; see also time.dayofweek.
// repeat every week on Tuesday and Friday|
• const monthlydate = Repeat monthly, at given dates.
Repeat the entry every interval months, on the days indicated by when.
// repeat every two months on the 10th and 25th|
• const monthlyday = Repeat monthly, at given days of weeks.
Repeat the entry every interval months, on the week days in the weeks indicated by when: when[2*i] indicates the week of the month (1 is the first, 4 is the fourth, 5 the last), and when[2*i+1] indicates the day of week (0 is Monday).
// repeat every month on the Tuesday (1) of the 2nd|
// week (2), and on the Tuesday (1) of the last week (5)
• const yearlydate = Repeat yearly, at a given date.
Repeat the entry every interval years, on the date implied by the entry's start date. This repeat type is typically used for anniversaries.
// repeat every year|
• const yearlyday = Repeat yearly, at a given day of a week of a month.
Repeat the entry every interval years, on the day indicated by when: when indicates the month, when the week of the month (1 ist the first, 4 is the fourth, 5 is the last), and when the day of week (0 is Monday).
// repeat yearly, on Sunday (6) of the 1st week in April|
• function add(entry) → Number
Add an entry to the agenda database, and return its id. The entry must be an array with keys from the above tables. The entry type is derived from the flags array element; if there is no flags element, an agenda.appt entry is added.
// Add a 30 minute meeting starting in two hours,|
// in the CEO's office
// Add an anniversary, repeating every year
e=["text": "Shakespeare's Birthday",
• function delete(id) → null
Delete the contact with the given id.
Throws ErrNotFound if there is no such contact.
// delete the anniversary added in the add example|
• function find(start=null, end=null, flags=agenda.appt | agenda.event | agenda.anniv | agenda.rep) → Array
Searches the agenda for entries overlapping with the period between start and end, and with an entry type indicated by flags. The default flags exclude to-do list entries.
Repeated entries are only reported if the first repetition falls within the period. Use agenda.findall to find all events within a period, including repetitions.
start and end must be given in seconds since year zero; start=null indicates the earliest possible start date, end=null the latest possible end date.
// get the number of entries in the agenda|
print len(agenda.find(null, null, agenda.all))
// print the text and start of today's entries
for id in agenda.find(today,today+86400) do
print e["text"], time.str(e["start"], "hh:mm")
// delete all entries up to now, excluding repetitives
Group meeting 18:40
for id in agenda.find(null, time.get(),
agenda.all & ~agenda.rep)
• function findall(start, end, flags=agenda.appt | agenda.event | agenda.anniv | agenda.rep) → Array
This is similar to agenda.find, except that all instances of repeated entries are reported if they fall within the period. The function returns an array with an element for each instance found. Each element is again an array with the following elements:
| Key||Meaning |
| id||The id of the entry, as returned by agenda.find. |
|at||The start time of the instance. For a non-repeated entry, this is the same as the entry's start time. For a repeated entry, this is the start time of the instance falling within the selected period. |
// print the text and start of today's instances|
for idtime in agenda.findall(today,today+86400) do
print e["text"], time.str(idtime["at"], "hh:mm")
Group meeting 18:40
Weekly Yoga session 20:30
• function get(id) → Array
Get the fields of the agenda entry with id id.
Throws ErrNotFound if there is no entry with this id.
// get the entry added before|
→ [Group meeting,1,63284611200,63284613000,
→ 2005-05-17 18:40:00
• function set(id, entry) → null
Updates the entry with id id, updating the fields in array entry. entry must be an array with keys from the above tables. Fields which are null in the array are cleared in the entry.
// Change the location of the group meeting|
agenda.set(402653204, ["loc":"My office"])
// Set all done entries in the to-do list to "not done"
ids=agenda.find(null, null, agenda.todo | agenda.done);
for id in ids do
Next: Module contacts: Contacts Database
© 2004-2011 airbit AG, CH-8008 Zürich