Function Name |
Minute | ||
Category |
DateTime | ||
Icon |
|||
Description |
Retrieve the minute portion of a DateTime value | ||
Inputs |
|
||
Outputs |
|
||
Properties |
|
The Data Mapper DateTime Minute function returns the minute portion of a DateTime value. Many applications use DateTime values to record information about events, for example to process data such as weather incidents. It is often necessary to retrieve particular portions of a DateTime value, such as the minute, or to separate the DateTime into its component parts for the target application. To apply the DateTime Minute function, use the following process:
Create a new Data Mapper file, dragging your XML data source and targets into the editor area. For this example we are using weather_source.xsd, an XML Schema Definition inferred from the following source:
Source XML |
Copy Code
|
---|---|
<events> <weather_event> <incident_type>Tidal Wave</incident_type> <severity>5</severity> <recorded>2005-10-23T08:20:45.57</recorded> </weather_event> <weather_event> <incident_type>Hurricane</incident_type> <severity>9</severity> <recorded>2007-09-14T11:40:12.44</recorded> </weather_event> </events> |
For our target schema we will be using weather_target.xsd, inferred from the following XML:
Target XML |
Copy Code
|
---|---|
<weather> <incident type="lightning" severity="7"> <time type="minute">12</time> </incident> <incident type="tornado" severity="10"> <time type="minute">39</time> </incident> </weather> |
The data models weather events, including the DateTime for when an incident was recorded. Let's assume that in this case we want to map the minute within the hour that each event occurred. Here is the Data Mapper with Source and Target imported:
Drag the DateTime Minute function from the Component Palette into the mapping area:
The Minute function takes a single input, the DateTime in question, giving an output comprising the minute portion. The input should be connected to the source item, which will normally be an item in the XML Reader. The output should be connected to the target item, whether an item in the XML Writer or another component in the Mapper, for example if you plan on using the minute value to sort or filter the data.
We want to map the "recorded" DateTime value to the "time" element in our target, so connect these between Reader and Writer.
Now connect the Minute function input also to the "recorded" output in the XML Reader and the Minute output to the Element Value for the "time" element in the XML Writer, so that the content of the element will be the minute part of the DateTime.
Remember that the target XML has an attribute in the "time" element indicating the type of time data in question. To add this, let's drag a Constant Value from the Data Type section onto the Mapper. Right-click it, choosing Show Properties. Select a String Data Type and enter "minute" as the value.
Now connect the Constant output to the "type" attribute input for the "time" element in the XML Writer.
Finally, connect the remaining inputs and outputs:
We can now execute the transform by pressing Shift-F5 or the Execute button (). The transform is applied and the file we selected as output opens in the editor:
Output XML |
Copy Code
|
---|---|
<weather> <incident type="Tidal Wave" severity="5"> <time type="minute">20</time> </incident> <incident type="Hurricane" severity="9"> <time type="minute">40</time> </incident> </weather> |
The output contains the minute portion of each DateTime value for a single incident, represented as a number between 0 and 59.
This is a scalar function so the standard rules apply if multiple values are presented to one or more inputs.