Method code for $world_time.from_english()

[Turn on line numbering]
arg string, @units;
var words, len, nsec, n, i, entry, unit;

[(units ?= time_units)] = units;
words = string.explode();
words = words.setremove_all(["and"]);
if (listlen(words) == 1) {
    if (!(words = regexp(words[1], "^([0-9]+)(.*)$")))
        throw(~args, "Invalid time.");
}
len = listlen(words);
if (len % 2)
    throw(~args, "Unrecognized time '" + string + "', no descriptor.");
nsec = (n = 0);
for i in [1 .. len] {
    if (i % 2 == 1) {
        if (words[i].is_numeric())
            n = words[i].to_number();
        else if (words[i] in ["a", "an"])
            n = 1;
        else if (words[i] == "no")
            n = 0;
        else
            throw(~invarg, "Invalid time element '" + n + "'.");
    } else {
        unit = words[i];
        unit = unit.strip(",");
        nsec += (> units[.parse_unit(unit, units)][1] <) * n;
    }
}
return nsec;

["// Created 19-Nov-1996 as a part of ColdCore, see: @help Credit"]

the Cold Dark