Split time string to value
(Replacing message template with parser tag)
(Updated Edited template to July 12, 2025.)
Line 13: Line 13:
Later, I found that this article addresses the same issue in a wider context together with the derived settable attribute here: [[Derived settable attributes]].
Later, I found that this article addresses the same issue in a wider context together with the derived settable attribute here: [[Derived settable attributes]].
[[Category:OCL]]
[[Category:OCL]]
{{Edited|July|12|2024}}
{{Edited|July|12|2025}}

Revision as of 06:03, 20 January 2025

This page was created by Hans.karlsen@mdriven.net on 2020-01-22. Last edited by Stephanie@mdriven.net on 2025-01-22.

I was asked how to split a string from a textbox to its given hour and minute values.

let x='22:12'.split(':'.tochararray) in
(
  Integer.Parse(x.at0(0)).asstring+' hours and '+Integer.Parse(x.at0(1)).asstring+' minutes'
)

Why, you ask? Well, consider having this in a ReverseDerived string representing the clock. Once you have the parts, you can update a Datetime value with these for storage.

Or maybe do something like this:

let x='22:12'.split(':'.tochararray) in(
  DateTime.Parse('0001-01-01 '+x.at0(0)+':'+x.at0(1))
)

Later, I found that this article addresses the same issue in a wider context together with the derived settable attribute here: Derived settable attributes.