3

The goal is to create a date and time picker for a viewmodel in MDriven.

Date-wise, this is easily achieved by making set variable of date type.

When it comes to the time aspects, it seems to be a little more tricky since a time type does not exist, for obvious reasons.

(Yes, before you suggest so, I have already read How do I set Date AND time picker in MDriven? and it did not help fully.

Context:

We have tried to work our way around this by letting the user write their desired time in a column of Int-form and implementing constraints that disallows users to write something other than that of "hhmm". Whilst this worked, it is not practical and slows down the user-experience.

Ideally, we would like to have a picklist where the user gets to chose pre-made times (i.e 16:00, 16:30, 17:00 etc). This way, the format of the chosen time would never break the framework in which we want to make use of the time later on, since it is limited.

Question:

How could this be attained? Surely there is a way to create constants (like hard-coded, solely visible variables), or perhaps you could collect instances of string with a specific operator for this use?

Ed Willink
  • 1,205
  • 7
  • 8
Gustaf
  • 147
  • 5

2 Answers2

1

I think you want a set of usual values to choose from. But possibly the chosen value could be changed by the user.

I would declare a class TimeValueStore. In this class I would have an attribute with only the time part set of a datetime, so 0000-00-00 16:00. I would add a admin UI to maintain these. (I can parse the DateTime back from a string with DateTime.Parse(vTimeStringValue)).

In the UI I can then have a combobox with TimeValueStore.allinstances. When the user changes the picked value in the combo the value can be assigned to a viewmodel variable vPickedTime.

I would also have a DateTimePicker that sets a date in vPickedDate.

In a button named "Apply" I would have this expression: self.TheDateTimeFinallyChoosen:=vPickedDate.Add(vPickedTime)

Hans Karlsen
  • 2,275
  • 1
  • 15
  • 15
  • This would be the most intuitive way attain this if it wasn't for the fact that DateTime doesn't give us a TimeStringValue. Is this a bug? – Gustaf Jul 06 '18 at 12:30
  • Also the Parse opperator does not appear, instead we have used .substring, not very practical, but works. – Gustaf Jul 06 '18 at 12:31
  • 1
    All objects - even DateTime - has the ToString() operator. In the case of DateTime the ToString also accepts a format-string like 'yyyy-MM-dd' – Hans Karlsen Jul 07 '18 at 08:50
  • 1
    Parse is a static operator (acts on the type) - try this: DateTime.Parse( '2018-01-02' ) in the debugger – Hans Karlsen Jul 07 '18 at 08:53
1

This doesn't solve the pick-list problem, but take a look at the example in Derived Settable attributes in the MDriven Wiki.

Using derived settable attributes might be a good way to remove complexity from the UI controls.

https://wiki.mdriven.net/index.php/Derived_settable_attributes

Lars
  • 191
  • 4