Fields - logical types


field_id, [”heading”], type & size [[dim1 [, dim2 [, dim3 [, dim4]]]]] \
[/logical] [,”format” [, flags [, “validation”]]]

Certain data types may be allocated a logical type, which affects the interpretation of the data they contain. The logical type follows the type and size (and dimension) of the field, and is preceded by the slash character /. Note that it should not be preceded by a comma. The logical type is part of the type & size specification.

Signed and unsigned integer fields (types u and i) may be used to store date, time and money-related data in a number of ways:

Type

Description

cy

Currency value.

dn

Date, stored as a day number where day 1 is 01/01/0001. The Sculptor system variable sys.Date, which stores the system date, is of this type.

ed

Elapsed days.

eh

Elapsed hours.

em

Elapsed minutes.

es

Elapsed seconds. The Sculptor system variable sys.SysTime, which stores the system time in seconds, is of this type.

el

Elapsed milliseconds.

eu

Elapsed microseconds.

my

Sculptor 2 type money value

td

Time and date, stored as seconds counting from midnight on 01/01/1970. This date has been selected because it is the standard for both DOS and UNIX. The Internet function gmt_std_format() is available to convert a td type field to an Internet standard GMT time and date value.

ts

Clock time, stored in seconds. The range is 00.00.00 (midnight) to 23.59.59. The maximum value for this field is therefore 86399, one fewer than the number of seconds in a day. The Sculptor system variable sys.Time, which stores the system time in seconds, is of this type.

These types can currently be defined for temporary fields only. Future versions of the data dictionary system will support them in file field definitions. However, logical types may be assigned to file fields by means of flags. See Assigning or retrieving logical type at runtime.


EXAMPLES

!temp StartDate,,i4/dn             /* Date */
!temp Ndays,"DAYS",i4/ed           /* Elapsed days*/
!temp ClockTime,"TIME",u3[10]/ts   /* Array of clock times */

Assigning or retrieving logical type at runtime

A logical type can be assigned to a field, or the existing type changed, by use of the form:

field_id->logical_type = flag

If the logical type of a field in a Sculptor keyed file declared by ![o]file is changed, and that file has one or more !record structures associated with it, the logical type of the equivalent field in the !record structure is changed accordingly. Similarly, if the logical type of a field in a !record structure associated with a file is changed, the type of the equivalent field in the file is also changed.

The available flags, which are contained in the standard include file $SCULPTOR/include/sculptor.h, are:

LT_NULL

No type

LT_ESECS

Elapsed seconds (es)

LT_DAYNO

Day number (dn)

LT_EMILS

Elapsed millisecs (el)

LT_DTIME

Date and time (td)

LT_EMICS

Elapsed microseconds 1

LT_EDAYS

Elapsed days (ed)

LT_TMILS

Clock time (milliseconds) 1

LT_EHOURS

Elapsed hours (eh)

LT_TSECS

Clock time (ts)

LT_EMINS

Elapsed minutes (em)

1(1,2)

These types currently can not be assigned in a field’s definition, but must be set at run time.

The logical type flags may also be tested against a field in order to retrieve its logical type, if any.


Arithmetic and assignment

It is important to be aware of the implications of performing arithmetical operations involving these fields and of making assignments from one type to another. In general, Sculptor handles data intelligently, converting the result of an operation to a new type where necessary. It also handles assignment from one date/time type to another, as long as the data falls within the ranges used by both types. Here are some examples:

Arithmetic

ts1 - ts2 > es

Subtraction of one clock time from another produces a result in elapsed seconds. Sculptor automatically allocates type es to the result of this operation.

ts1 + ts2

This operation makes no sense, and produces a number with no logical type

ts1 +|- es > ts2

Elapsed seconds added to or subtracted from clock time result in another clock time. Wrapping is automatic: 23.50.00 + 12 minutes results in 00.02.00.

dn1 + ed > dn2

Elapsed days added to a date results in another date.

td1 +|- ed = td2

The date of td2 will differ from td1 by the value of ed, but the clock time will be the same.


Assignment

es = el

The value of em is divided by 1000.

es = ed

The value of ed is multiplied by 86400.

dn = td

The clock time part of td is dropped, and the date adjusted to dn type.

ts = td

The clock time is extracted from td.

td = dn

If the date represented by dn is earlier than 01/01/1970, no conversion can be made and the result is 0. Otherwise, the date is assigned to td, with a clock time of midnight.

A set of useful definitions for use with time calculations is provided in <sculptor.h>

Since Sculptor 6.4.0, a convenience todate() helper function has been added to the Sculptor language, that makes possible to compare an i4/dn field directly against a date string.


RELATED TOPICS

Data fields

Date configuration

Date formats

Time formats

todate()