AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
Calendar typedict
 
A Calendar is the Yoix representation of the Java GregorianCalendar class. A Calendar object is used to facilitate date/time arithmetic and other calendar oriented manipulations including conversion to and from time values of the sort returned by the time built-in. Taken together, the fields in a Calendar give a consistent representation of an instant in time as indicated by the unixtime field and adjusted according to the specified timezone information. The complete set of fields in a Calendar are:
add(int flag, int amount) Adds amount to the component of this calendar specified by flag. The set of flag values can be found in yoix.util.Calendar. There is no return value.

For example, the following code:

import yoix.stdio.*;
import yoix.util.*;

Calendar c;

printf("Calendar is currently:\t\t\t%s\n", date(c.unixtime));
c.add(Calendar.MONTH, 15);
printf("Calendar after adding 15 months:\t%s\n", date(c.unixtime));
c.add(Calendar.DATE, -150);
printf("Calendar after subtracting 150 days:\t%s\n",
       date(c.unixtime));
writes something like the following to standard output:
Calendar is currently:                  Tue Oct  3 14:26:08 EDT 2006
Calendar after adding 15 months:        Thu Jan  3 14:26:08 EST 2008
Calendar after subtracting 150 days:    Mon Aug  6 14:26:08 EDT 2007
ampm A read-only int that is zero if the given time is in the morning (AM) and non-zero if the given time is in the afternoon (PM).
date Identical to the dayofmonth field.
dayofmonth An int indicating the appropriate day of the month, where 1 represents the first day of the month. Reading gives the current date value. Writing immediately sets the date to the new value. Setting a value that is outside the range of the current month, appropriately adjusts the calendar when lenient is non-zero. For example, when the calendar is currently in July, then setting the date to 32 positions the calendar at August 1, while setting the date to -1 positions the calendar at June 29.
dayofweek A read-only int indicating the appropriate day of the week, where 1 represents Sunday and 7 represents Saturday.
dayofweekinmonth A read-only int indicating the appropriate week in the month in which the given date/time falls. Counting is from the first day of the month so that dates 1 through 7 have a dayofweekinmonth of 1, and so on, regardless of the day of the week on which the first day of the month fell.
dayofyear An int indicating the appropriate day of the year counting from 1, namely the value for the first of January is 1. Reading gives the current day of the year value. Writing immediately sets the day of the year to the new value. Values outside the current year range will appropriately adjust the calendar when lenient is non-zero. For example, setting the value to 0 sets the calendar to December 31 of the previous year.
dstoffset A read-only int indicating the value of the daylight savings time offset in effect based on the supplied timezone information. The value is in milliseconds and indicates the amount added to standard time for the current date/time value.
era An int that is zero if the given time is before the Christian era and one if it is in the Christian era. Reading gives the current era of the calendar. Writing immediately sets the era to the new value.
firstdayofweek An int indicating which day is considered the first day of the week as determined from the supplied locale information. Reading gives the current value. Writing immediately sets the new value, but does not otherwise affect the calendar.
gregorianchange A double indicating the time when the switch from Julian dates to Gregorian dates occurred. Reading gives the current value. Writing immediately sets the new value, but does not otherwise affect the calendar.
hour A read-only int indicating the hour of the day on a 12-hour clock.
hourofday An int indicating the hour of the day on a 24-hour clock. Reading gives the current hour value. Writing immediately sets the new hour value. Values outside the range 0 to 23 cause the calendar to adjust appropriately when lenient is non-zero.
leapyear A read-only int that is zero if the indicated year is not a leap year and non-zero otherwise.
leastmaximum(int flag) Returns an int that is the smallest value in the set of maximum values for the component of this calendar specified by flag. The set of flag values can be found in yoix.util.Calendar.

For example, the smallest number of days in a month can be found as follows:

import yoix.stdio.*;
import yoix.util.*;

Calendar c;

printf("A month will have at least %d days.\n",
       c.leastmaximum(Calendar.DAY_OF_MONTH));
puts("Note that leap year is not taken into account.");
with the result:
A month will have at least 28 days.
Note that leap year is not taken into account.
lenient An int that is non-zero if conversion from supplied date information is to be lenient and zero if it is to be strict. Strict conversion means that a date specified as January 32nd is an error, whereas lenient conversion would take it to mean February 1st.
locale A Locale object that provides firstdayofweek and minimaldaysinfirstweek information to the Calendar. Reading gives the current locale information. Writing immediately sets the locale to the value.
maximum(int flag) Returns an int that is the maximum value for the component of this calendar specified by flag. The set of flag values can be found in yoix.util.Calendar.

For example, the largest number of days in a month can be found as follows:

import yoix.stdio.*;
import yoix.util.*;

Calendar c;

printf("A month will have at most %d days.\n",
       c.maximum(Calendar.DAY_OF_MONTH));
with the result:
A month will have at most 31 days.
millisecond An int indicating the millisecond portion of the current date/time. Reading gives the current millisecond value. Writing immediately sets the new millisecond value. Values outside the range 0 to 999 cause the calendar to adjust appropriately when lenient is non-zero.
minimaldaysinfirstweek An int indicating the minimum number of days required in the first week of the year for it to be considered a week within this year. Reading gives the current value. Writing immediately sets the new value.
minimum(int flag) Returns an int that is the minimum value for the component of this calendar specified by flag. The set of flag values can be found in yoix.util.Calendar.

For example, the least number of days in a month can be found as follows:

import yoix.stdio.*;
import yoix.util.*;

Calendar c;

printf("A month has at least %d day%s.\n",
       (n=c.minimum(Calendar.DAY_OF_MONTH)), (n==1?"":"s"));
puts("No surprise there.");
with the result:
A month has at least 1 day.
No surprise there.
minute An int indicating the minute portion of the current date/time. Reading gives the current minute value. Writing immediately sets the new minute value. Values outside the range 0 to 59 cause the calendar to adjust appropriately when lenient is non-zero.
month An int indicating the month of the year with the first month, January, starting at 0. Reading gives the current minute value. Writing immediately sets the new minute value. Values outside the range 0 to 11 cause the calendar to adjust appropriately when lenient is non-zero.
roll(int flag, int up) Cycles with increasing values, if up is non-zero, or decreasing values, if up is zero, through all possible values for the calendar component specified by flag. Unlike add, roll will not cause other fields to be incremented or decremented. Though other components may be affected to keep the date / time information consistent, one can just keep cycling through all the values of the particular component indicated until the original value repeats at which point the date / time will be back to its original value. There is no return value.

For example, the following code can be used to cycle through all the days of the current week as follows:

import yoix.stdio.*;
import yoix.util.*;

Calendar c;

printf("Calendar is currently:\t\t%s\n", date(c.unixtime));

int start_date = c.date;

c.roll(Calendar.DATE, true);

do {
    printf("Cycling up by 1 day yields:\t%s\n", date(c.unixtime));
    c.roll(Calendar.DAY_OF_WEEK, true);
} while(c.date != start_date);
with the result:
Calendar is currently:          Tue Oct  3 15:43:19 EDT 2006
Cycling up by 1 day yields:     Wed Oct  4 15:43:19 EDT 2006
Cycling up by 1 day yields:     Thu Oct  5 15:43:19 EDT 2006
Cycling up by 1 day yields:     Fri Oct  6 15:43:19 EDT 2006
Cycling up by 1 day yields:     Sat Oct  7 15:43:19 EDT 2006
Cycling up by 1 day yields:     Sun Oct  1 15:43:19 EDT 2006
Cycling up by 1 day yields:     Mon Oct  2 15:43:19 EDT 2006
second An int indicating the second portion of the current date/time. Reading gives the current second value. Writing immediately sets the new second value. Values outside the range 0 to 59 cause the calendar to adjust appropriately when lenient is non-zero.
set(int year, int month, int date[, int hour, int minute[, int second]]) A convenience built-in for setting several elements of the calendar's date / time value in one action. At a minimum, the year, month and date must be supplied. The hour and minute, and optionally, second can also be supplied. Bear in mind that the first month is represented by zero while the first day of a month is represeted by one. There is no return value.
timezone A TimeZone object that provides timezone information to the Calendar, including offset from GMT and daylight savings time offset and starting/ending information. Reading gives the current timezone information. Writing immediately sets the new timezone information.
unixtime A double that gives the number of seconds and, decimally, milliseconds since January 1, 1970 00:00:00.0 GMT. Reading gives the current unixtime equivalent for this calendar. Writing immediately sets the new unixtime for this calendar. Setting the unixtime value is a convenient way to set all the time elements of the calendar at once.
weekofmonth A read-only int whose value depends on how firstdayofweek and minimaldaysinfirstweek are set. If, for example, the date/time is the first of some month and it is a Saturday and firstdayofweek is set as Sunday and minimaldaysinfirstweek is set as 1, then weekofmonth is 1. If minimaldaysinfirstweek is set as 2, however, then weekofmonth is 0. With minimaldaysinfirstweek set as 2 and firstdayofweek set as Monday, though, weekofmonth goes back to 1. Regardless of how minimaldaysinfirstweek is set, as the date/time is increased the count of weekofmonth goes up by 1 as each intervening firstdayofweek is crossed.
weekofyear Like weekofmonth, weekofyear is a read-only int whose value depends on how firstdayofweek and minimaldaysinfirstweek are set to determine whether counting starts from 0 or 1 and when the counter is incremented. For January, this value is identical with weekofmonth. For subsequent months, however, it is not affected by changes in the month value, but rather continues to be incremented for each intervening firstdayofweek.
year An int indicating all-digits of the year portion of the current date/time. Reading give the current year value. Writing immediately set the year to the new value.
zoneoffset A read-only int indicating the value of the timezone offset from GMT based on the supplied timezone information. The value is in milliseconds and indicates the amount added to GMT time to get the value for that time zone. Thus, for the United States Eastern timezone, the offset would be -18000000, indicating that for standard time 5 hours need to be subtracted from GMT to obtain EST.
Several permanent fields have not been documented and should not be used in Yoix applications.
 
 Example:   The program,
import yoix.stdio.*;

Calendar c = {
    double unixtime = yoix.system.time();
};

printf("Today is day %d of the year %d %s\n",
       c.dayofyear, c.year, (c.era ? "C.E." : "B.C.E."));
creates a calendar using the default Locale and Timezone and the current time and then prints something like,
Today is day 276 of the year 2000 C.E.
on standard output.
 
 See Also:   compareCalendar, date, getCalendarLocales, getDateFormat, getLocale, getTimeZone, getTimeZoneIDs, Locale, parseDate, setLocale, setTimeZone, TimeZone

 

Yoix is a registered trademark of AT&T Inc.