[i7] Wait until time

Hi all,

I’ve implemented the standard ‘wait until [time]’,

Understand "wait until [time]" as hanging around until. etc.....

and it works fine. So,

wait until 2:35 pm
is spot on.

however,

wait until 2:35
doesn’t work. Well, it sort of works, but it’s not ‘stopping’ at the right time.

Is there a way of parsing the [time] part of the command so that it checks to see if it’s a valid ‘time’, and then appends a ‘pm’ if there isn’t one?

Thanks for any help. Tried a bunch of stuff, but am banging my head on this one. Probably something really simple too!

I started out with ‘wait until [text]’ then tried to write a text_to_time function, but hit a wall. and I’m probably going far too around the houses.

McT

(When you ask a question like this, please say what the code does do and why it’s wrong. Thanks.)

What you’re seeing is that the time-parsing code assumes that a bare time (without “am/pm”) must be within the range 1AM to 12:59PM. This is a strange policy and I don’t know the reason for it.

Below I’ve pasted replacement code which assumes the intended time will be in the next twelve hours (as opposed to the previous twelve hours).

The Kitchen is a room.

Noting is an action applying to one time.
Hanging around until is an action applying to one time.

Understand "note [time]" as noting.
Understand "wait until [time]" as hanging around until.

Report noting:
	say "You said [the time understood] (currently [time of day])."

Report hanging around until:
	now the time of day is the time understood;
	say "You wait until: [time of day]."

Test me with "note 3 / note 10 / note half past eleven / note noon / note midnight / note 2:30 AM / note 3 PM / note 20:05".

Include (-

! Unchanged from the routine in TIme.i6t.
[ TIME_TOKEN first_word second_word at length flag
	illegal_char offhour hr mn i original_wn;
	original_wn = wn;

	wn = original_wn;
	first_word = NextWordStopped();
	switch (first_word) {
		'midnight': parsed_number = 0; return GPR_NUMBER;
		'midday', 'noon': parsed_number = TWELVE_HOURS;
		return GPR_NUMBER;
	}
	! Next try the format 12:02
	at = WordAddress(wn-1); length = WordLength(wn-1);
	for (i=0: i<length: i++) {
		switch (at->i) {
			':': if (flag == false && i>0 && i<length-1) flag = true;
			else illegal_char = true;
			'0', '1', '2', '3', '4', '5', '6', '7', '8', '9': ;
			default: illegal_char = true;
		}
	}
	if (length < 3 || length > 5 || illegal_char) flag = false;
	if (flag) {
		for (i=0: at->i~=':': i++, hr=hr*10) hr = hr + at->i - '0';
		hr = hr/10;
		for (i++: i<length: i++, mn=mn*10) mn = mn + at->i - '0';
		mn = mn/10;
		second_word = NextWordStopped();
		parsed_number = HoursMinsWordToTime(hr, mn, second_word);
		if (parsed_number == -1) return GPR_FAIL;
		if (second_word ~= 'pm' or 'am') wn--;
		return GPR_NUMBER;
	}
	! Lastly the wordy format
	offhour = -1;
	if (first_word == 'half') offhour = HALF_HOUR;
	if (first_word == 'quarter') offhour = QUARTER_HOUR;
	if (offhour < 0) offhour = TryNumber(wn-1);
	if (offhour < 0 || offhour >= ONE_HOUR) return GPR_FAIL;
	second_word = NextWordStopped();
	switch (second_word) {
		! "six o'clock", "six"
		'o^clock', 'am', 'pm', -1:
			hr = offhour; if (hr > 12) return GPR_FAIL;
		! "quarter to six", "twenty past midnight"
		'to', 'past':
			mn = offhour; hr = TryNumber(wn);
			if (hr <= 0) {
				switch (NextWordStopped()) {
					'noon', 'midday': hr = 12;
					'midnight': hr = 0;
					default: return GPR_FAIL;
				}
			}
			if (hr >= 13) return GPR_FAIL;
			if (second_word == 'to') {
				mn = ONE_HOUR-mn; hr--; if (hr<0) hr=23;
			}
			wn++; second_word = NextWordStopped();
		! "six thirty"
		default:
			hr = offhour; mn = TryNumber(--wn);
			if (mn < 0 || mn >= ONE_HOUR) return GPR_FAIL;
			wn++; second_word = NextWordStopped();
	}
	parsed_number = HoursMinsWordToTime(hr, mn, second_word);
	if (parsed_number < 0) return GPR_FAIL;
	if (second_word ~= 'pm' or 'am' or 'o^clock') wn--;
	return GPR_NUMBER;
];

! Altered version of HoursMinsWordToTime. If "am/pm" is not provided, this assumes the intended time will be in the next twelve hours (as opposed to the previous twelve hours).
[ HoursMinsWordToTime hour minute word x;
	if (hour >= 24) return -1;
	if (minute >= ONE_HOUR) return -1;
	x = hour*ONE_HOUR + minute;
	if (hour >= 13 || hour == 0) return x;  ! must be 24-hour time
	x = x % TWELVE_HOURS;
	if (word == 'pm') x = x + TWELVE_HOURS;
	if (word ~= 'am' or 'pm') {
		if ((x > the_time && x <= the_time+TWELVE_HOURS) || (x > the_time-TWENTY_FOUR_HOURS && x <= the_time-TWELVE_HOURS)) {
			! x is in the coming twelve hours
		}
		else {
			! x is in the preceding twelve hours
			x = (x + TWELVE_HOURS) % TWENTY_FOUR_HOURS;
		}
	};
	return x;
];

-) instead of "Understanding" in "Time.i6t".

Thank you!