Next -> Responding to Client-Side Data
Now it starts to get good... In this section, I'm going to show you how to return different values from your script in response to specific conditions. You can use this kind of script to do all sorts of nifty stuff. In this case, we're going to set up a script that returns a greeting based upon the time of day.
In order to tackle this, we're going to need more research than we did in the last chapter. To pull this off, we need to
Because it is localized to so many languages, the NewtonOS has a really powerful system for dealing with dates and times. Newton keeps time in one of two ways:
For our purposes, we'll use Time In Minutes since it's the most general and we don't need seconds resolution.
Time in Minutes is pretty useless to humans: We're best at dealing with values like day, week, month, hours, and so on. In every language, the word for these values is different so the core of the Newton date system is the Date Frame3 which is a frame containing month, week, day, hour, minute, etc as integers.
You create a date frame with this kind of
Newtonscript: Date(integer time in seconds)
To get today's date, we'd do
Date(Time());
which returns on March 9, 1999 3:18 PM this date frame:
{
   year: 1999,
   month: 3,
   Date: 9,
   dayOfWeek: 2,
   hour: 15,
   minute: 18,
   second: 0,
   daysInMonth: 31
   }
To access just the hour slot of the frame,
you'd use Date(time()).hour and that's just what we'll
do.
Here are out rules for dividing the day up:
| 
          Name: Greetings  | 
      
          SSI: TIMEGREET  | 
   
| 
          
 
 //Allocate the second part of the greeting 
  | 
   |
1.NPR: 17-21
2.NPR: 17-22
3.NPR: 17-27
4.NPL: 3-1 to 3-3