There are several possible solutions to this. The first is to disable the numeric checking in the context by doing the following:
Context()->{pattern}[number} = '^$'; Context()->update;This will make the number pattern be blank, which will never match anything (since a match it attempted only when there actually is something to match against). This should allow your time strings to be matched. Note, however, that by default your context also has definitions for all the operators (+, - , *, etc), functions (sin(), cos(), etc), constants (e, pi), and so on, so student could type these and get strange error messages. So you might want to remove them, as follows:
Context()->strings->clear; Context()->constants->clear; Context()->variables->clear; Context()->functions->clear; Context()->operators->clear; Context()->parens->clear;before adding your time strings to the context. This will make it impossible to type anything but time strings. However, you will still get some bad error messages (things like "Unexpected character '+'" if you type a plus). To solve that problem, you might use
Context()->{error}{msg}{"Unexpected character '%s'"} = "Your answer doesn't look like a time value"; Context()->{error}{msg}{"'%s' is not defined in this context"} = "Your answer doesn't look like a time value";to translate those messages into a less precise, but perhaps less confusing, message.
Since you are using a List later on, you will want to allow the comma operator, so you can redefine it using
Context()->operators->redefine(',',from=>"Numeric");Finally, you might want to make aliases like "1AM"=>{alias=>"1 AM"} so that the space can be left out, since the space is required in the current form.
An alternative approach would be to declare a variable called "AM" and one called "PM", so that "1 AM" would really be "1*AM". You could adjust the output of the implicit multiplication using
Context()->operators->set(" "=>{string=>" ",TeX=>"\ ",perl=>"*");so that it would display properly in the preview and hardcopy. This would solve the problem of allowing spaces, and would allow mathematical operations in the hour (as in "5+3 am"), but it would not handle switching from AM to PM correctly, and you could do unusual things like "3 AM^2" or "AM 3" or just plain "AM" and not get an error message. You could also get error messages that suggest you should enter a formula (since the AM is a variable), and that might be confusing.
You suggest that what you want to do is set a new Unit for this. That is a nice idea, but I don't think that will quite work, because the way the unit library works by using multiplicative factors to convert the student's and professor's answers to a common unit, but the AM/PM difference is additive, not multiplicative.
There really needs to be a time-value context, so I'll put that on my list of things to work on .
Davide