Click on a class name to see the description of that particular class:
Supports manipulation of date and time in various formats.
The time class supports manipulation of date and time in various formats.
“Time Zero”: in general, a certain time point is identified by a computer as the number of seconds (or ticks – one tick is 1/60th of a second) from a certain “time zero” or “ epoch time”, which varies from system to system. In many UNIX version this corresponds to 00:00:00 GMT (Greenwich Mean Time) of January 1, 1970. On Mac OS time zero is midnight of January 1st, 1904. Biferno adopts the convention of using 00:00:00 of January 1, 1970 as the time zero for the time class.
The above technique to represent an instant in time, i.e. a date including the time with second precision, is called timestamping.
Operations on dates and times are also supported. The individual elements of an object of the time class can be incremented or decremented, and dates and times can be added or subtracted. This example shows how to compute tomorrow’s date:
tomorrow = time()
tomorrow.day++ // Increment the current day by 1
An alternative is:
tomorrow = time()
tomorrow.hour += 24 // Add 24 hours to the current time
To add two objects of the time class means to add the respective timestamps.
If the value resulting from an operation is outside of the allowed range, the value is automatically adjusted, as in:
tomorrow = time("31/1/2001")
// the tomorrow variable contains the value: 1/2/2001
|void time(string timeString, string formatString)|
Initialize a time object
Initializing a time class variable means to create an object associated to a certain timestamp. To associate the current server date and time to a variable, we will write:
now = time()
If we print the now variable we obtain an output similar to the following:
This is the string representation of the current timestamp when the variable was initialized. This string is returned by the implicit string conversion method of the time class.
A time class variable can also be initialized passing to the constructor a string representing a valid date and time, and an optional format string. In this case the created object is associated to the timestamp corresponding to the specified date. If the string supplied to the constructor doe not correspond to a valid date, an error message is generated. An example is:
date1 = time("24-3-1974")
date2 = time("24/3/1974 15:30", "d/m/y")
date3 = time("3-24-1974 15.30.00", "m-d-y h.")
The format string, if present, determines the order in which day (d), month (m) and year (y) appear in the date string and the separator character used (typically a dash or slash, other characters can be used). The hours, minutes, seconds separator can be specified after the h character (see third line in the previous example). The default format depends on the operating system settings (can be, for example, "d-m-y h:" or "m-d-y h."). This value can be altered by modifying the application variable DATE_FORMAT in the “Biferno.config.bfr” configuration file and assigning it the format string that we want as default for our application. An example is:
DATE_FORMAT = "y/m/d h:"
Dates that fall between Biferno’s time zero and December 31st, 2036 are handled correctly by Biferno. A date outside of these bounds can be passed to the constructor of the time class, but some properties and methods, in particular those executing conversions and formatting, may report erroneous data.
the string representing the time
the format of the time string