Some of this code is from Deutha's original amtime() simul_efun and
some from the am_time_array() efun which Macchirton wrote, although the
latter has mostly been rewritten.
-
interpret_time_string
varargs int interpret_time_string(string time_str,
int real_time)
This method takes a time string and returns the number of seconds
that that string represents. If the second argument is passed and
is nonzero, then real-life time is used. It is otherwised
interpreted as Ankh-Morpork time. Note that the string
number parsing is simple its threshold is ninety-nine.
- Parameters:
time_str - the actual string
real_time - if this is specified and nonzero, then real-life
time will be used, otherwise Ankh-Morpork time
- Returns:
returns an integer value that represents the number of
seconds that the string represents (or -1 on failure)
- See also:
query_time_string()
- Example:
query_time_string ("1 minute")
query_time_string ("1 hour and 30 minutes")
query_time_string ("1 year, 2 days and 40 minutes")
query_time_string ("one year and three hours", 0, 1)
-
query_am_hour
int query_am_hour(int time)
This method returns the hour of the day in Ankh-Morpork.
- Parameters:
time - time to convert ( as would be returned by time() )
- Returns:
the hour of the day in Ankh-Morpork in 24 hour clock
- See also:
time.c, query_am_minute.c and query_am_time_array
.c
-
query_am_minute
int query_am_minute(int time)
This method returns the minute of the day in Ankh-Morpork.
- Parameters:
time - time to convert ( as would be returned by time() )
- Returns:
the minutes passed since midnight in Ankh-Morpork
- See also:
time.c, query_am_hour.c and query_am_time_array
.c
-
query_am_time
string query_am_time(int number,
int format)
This method returns the amtime for the input time number. This function takes
the same input as the efun ctime(). You pass in the time number and
it returns a string detailing the time in ankh morpork.
- Parameters:
number - the time number
format - the format additions to use in the output
- Returns:
a string containing the amtime
-
query_am_time_array
int * query_am_time_array(int number)
This is a simple way to get a helpful array of values
for the time in Ankh-Morpork (depreciated). Useful in functions
you want to act differently for different days, months,
etc. It returns a five element array as described below.
The return values are similar to those used with
localtime().
THIS METHOD IS DEPRECIATED, USE am_time_class() INSTEAD.
- See also:
efun::time(), efun::localtime(), amtime() and /include/am_time.h
-
query_am_time_class
class am_time query_am_time_class(int number)
This is a simple way to get a helpful array of values
for the time in Ankh-Morpork. Useful in functions
you want to act differently for different days, months,
etc. It returns a class as described below.
The input parameter to this function should be the return
result from a time() system call.
class am_time {
- int month ->
- 1 = Offle
- 2 = February
- 3 = March
- 4 = April
- 5 = May
- 6 = June
- 7 = Grune (incl. Small gods day)
- 8 = August(incl. Soul cake tuesday)
- 9 = Spune
- 10 = Sektober
- 11 = Ember
- 12 = December
- 13 = Ick
- int day_of_month
- int day_of_weekh
- 1 = Monday
- 2 = Tuesday
- 3 = Wednesday
- 4 = Thursday
- 5 = Friday
- 6 = Saturday
- 7 = Sunday
- 8 = Octeday
- int hour
- int minute
- int year
- int primus
ie:
- Parameters:
- number the time you want to create the array for
- Returns:
returns the class of the Ankh-Morpork time array
- See also:
efun::time(), efun::localtime(), amtime() and /include/am_time.h
- Example:
// Here's an example of part of the code for a
// room that looks different on Wednesdays.
inherit "/std/room";
#include
string query_the_long();
void setup(){
...
// Setup a function pointer for the long description.
// This is so it can change dynamically
set_long( (: query_the_long() :));
...
} /* setup() */
// This method returns the dynamically changing long
// for the room. It says somethingf different evry
// Wednessday
string query_the_long() {
class am_time am_time;
am_time = am_time_class(time());
if (am_time->day_of_weed == AM_TIME_WEDNESSDAY){
return "A festival is in full swing, in honour "
"of the Great Coder MacChirton here, "
"with much haggis and bagpipes.\n";
}
return "This town is rather boring, and the streets "
"are abandoned.\n";
} /* query_the_long() */
-
query_am_time_from_array
string query_am_time_from_array(int * arr)
This method takes an array generated from am_time_array() as an input
to create the return string.
- Parameters:
arr - the array to turn into a string
- Returns:
the nice string
-
query_am_time_from_class
string query_am_time_from_class(class am_time arr,
int format)
This method takes an array generated from am_time_array() as an input
to create the return string.
- Parameters:
arr - the array to turn into a string
format - any format specifiers
- Returns:
the nice string
-
query_day_of_week
string query_day_of_week(int day_of_week)
This method returns the string of the day of the week.
- Parameters:
day_of_week - the day of the week
-
query_days_per_month
int * query_days_per_month()
This method returns an array of days per month.
-
query_hour_minute
string query_hour_minute(int hour,
int minute)
This method returns the hour/minute as a string. It adds the am/pm
bits to the number.
- Parameters:
hour - the hour of the day
minute - the minute of the hour
- Returns:
the hour/minute string
-
query_month
string query_month(int month)
This method returns the month passed in as a string.
- Parameters:
month - the month to return
- Returns:
the month as a string
-
query_special_day
string query_special_day(int month,
int day_of_month,
int primus)
This method returns the day of month as a string. This uses both the
month and the day of the month to get the correct strings for
special am days.
- Parameters:
month - the month to print out
day_of_month - the day in the specific month
primus - if it is the primus or secondus bit
- Returns:
the primus or secondus bit