Magic tags for temporal types

Temporal types have so called magic tags which allow to extract some specific values from temporal values. Magic tags behave somewhat like tuple fields, for example:

    @: t := (@)"2014-09-11T14:59:00";
    `print t.year;                   // Output: 2014
    `print t.week_day;               // Output: 4
    |: i := (|)[t, (^)"P1W"];
    `print i.end;                    // Output: 2014-09-18T14:59:00
    `print i.end.week_day;           // Output: 4
         

Note that some magic tags (like .end on intervals in the above example) return a value of temporal type to which another magic tag can be applied (i.end.week_day in the example above). The four tables below list the magic tags available for the four temporal types: time, absolute, relative and interval.

Table 4.5. Magic tags defined on @

Magic TagTypeExplanation
.jd& Julian Day: a real holding the number of days (and day fraction) since the start of the year 4713 BC (proleptic Julian calendar). For example, the .jd of the start of 2013 would be 2.456,294e+06.
.year# The year of a given point in time.
.month# The month of a given point in time.
.month_day# The day of the month of a given point in time.
.hour# The hour of a given point in time.
.minute# The minute of a given point in time.
.second# The seconds of a given point in time.
.week# The week number of a given point in time, where Monday is the first day of the week and January 4th is in the first week of the year. Note that some years have 53 weeks and others have 52 weeks. This is also known as ISO week number.
.week_day# The day of the week of a given point in time, where Monday is day number one and Sunday is day number seven.
.week_year# The year the week of a given point in time belongs to. This might seem unintuitive that a day of one year might be part of a week in another year. But since only about one in seven of the years start on a Monday, some days at the beginning of the year (specifically January 1st through January 3rd) can belong to the last week of the previous year. Likewise, December 29th through December 31st can be part of the first week of the next year.
.year_day# The day of the year of a given point in time. For example, the .year_day of August 20th of 1966 is 232.
quarter# The quarter of a given point in time.
.yyyyddd# The year multiplied by 1,000 plus the year day of a given point in time. Useful for things like comparing or selecting times.
.yyyyww# The year multiplied by 100 plus the week number of a given point in time. Useful for things like comparing or selecting times.
.yyyymm# The year multiplied by 100 plus the month number of a given point in time. Useful for things like comparing or selecting times.
.hhmm# The hour multiplied by 100 plus the number of minutes of a given point in time. Useful for things like selecting times.
.hhmmss# The hour multiplied by 10,000 plus the minutes multiplied by 100 plus the number of seconds of a given point in time. Useful for things like selecting times.


Table 4.6. Magic tags defined on ^

Magic TagTypeExplanation
.jds& Duration in Julian days. Note that this is a real. For the integer number of days, cast (maybe with rounding) to a number. For the fractional part use modulo.
.weeks# The duration in integer number of weeks. The duration can be up to (but not including) seven days longer.
.days# The duration in integer number of days. The duration can be up to (but not including) one day longer.
.hours# The duration in integer number of hours. The duration can be up to (but not including) one hour longer.
.minutes# The duration in integer number of minutes. The duration can be up to (but not including) one minute longer.
.seconds# The duration in integer number of seconds. The duration can be up to (but not including) one second longer.


Table 4.7. Magic tags defined on ~

Magic TagTypeExplanation
.r'months# Duration in months of the relative part.
.a'jds& Duration in Julian days of the absolute part. Note that this is a real. For the integer number of days, cast (maybe with rounding) to an number. For the fractional part use modulo.
.a'weeks# The duration in integer number of weeks of the absolute part. The duration can be up to (but not including) seven days longer.
.a'days# The duration in integer number of days of the absolute part. The duration can be up to (but not including) one day longer.
.a'hours# The duration in integer number of hours of the absolute part. The duration can be up to (but not including) one hour longer.
.a'minutes# The duration in integer number of minutes of the absolute part. The duration can be up to (but not including) one minute longer.
.a'seconds# The duration in integer number of seconds of the absolute part. The duration can be up to (but not including) one second longer.


Table 4.8. Magic tags defined on |

Magic TagTypeExplanation
.begin@ Begin time of the interval. Note that as a time it has its own magic tags. So i.begin.year would be a valid expression if i were a valid interval value.
.end@ End time of the interval. Note that as a time it has its own magic tags. So i.end.quarter would be a valid expression if i were a valid interval value.
.absolute^ Absolute duration of the interval. Note that as a time it has its own magic tags. So i.absolute.weeks would be a valid expression if i were a valid interval value.
Note: there is no relative magic tag because there is no way to arrive at a unique one. It is however possible to get one of the possible relative difference by using i.end ~ i.begin but its hard to imagine a real-life usage for that.