ZEN : Allow multiple date formats in a dateText control and converting them to the YYYY-MM-DD - intersystems-iris

There is a finite list of date formats that users want to use to enter a date in a form. These formats include single digits for month and day and double digits for year. The field is represented by a dateText control.
How would one get to allow a dateText control to accept multiple date formats ? I see only 3 listed (https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GZCP_forms_dateText), do those include using single digits for month and day ?
I tried to set the value of format = "#(myPageProperty.myValue)# " but I got a compilation error in Studio so that went nowhere. Has anyone ever been able to set the format value depending on the user input value?
I am guessing that the control input value must be converted to the YYYY-MM-DD before validation. I am open to calling a javascript function to do that but where would be the best place to put it?

for details see Class %ZEN.Component.dateText
setting format:
Property format As %ZEN.Datatype.string(MAXLEN = 3, **VALUELIST = ",MDY,DMY,YMD",** ZENEXPRESSION = 1)
you have exactly 3 formats or ""
Your guess on values is correct and documented:
/// The value of this control is always in the canonical form: YYYY-MM-DD
As this is one of the oldest components of ZEN your only chance to achieve
your way of operation is to create your own version inheriting from
Class %ZEN.Component.dateText and overloading the parts you want to change

Related

Convert date format, BMC Remedy/smart-it

Problem:
In a field called $Detailed Decription$ sometimes dateformat 08/09/2021 is enterd and this need to be converted to swedish format 2022-02-11
I'am going to use BMC Developer studio and make a filter but i cant find a fitting solution for it. Replacing it wont work (i think) becaus it need to have a value to replace it with.
Maby there can be a function that reads regex (\d{2})/(\d{1,2})/(\d{4}) but how can i convert it?
If it's sometimes - look at AR System User Preferencje form. Check certain user's locale and date time config.
Also is important where the data comes from. Could be a browser setting or java script mod.
1- Using Set fields action, copy the date value from Detailed Description to a Date/Time field (i.e. z1D_DateTime01).
2- Using Set fields action and Functions (MONTH, YEAR, DAY, HOUR, MINUTE, SECOND) you can parse the date/time and convert it to format you like.
Something like this:
SwedishDate = YEAR($z1D_DateTime01$) + "-" + MONTH($z1D_DateTime01$) + "-" + DAY($z1D_DateTime01$)
This will capture the parts of date and combine them with "-" in the middle and in the order you want.

Formatting date to a particular type in zapier cli

In my inputFields of zapier, there's one field where the user can enter the date but I want the zapier to work only if I write the date in "2020-09-18T15:30" otherwise it should show a message that the data entered does not match the format specified. I tried this but it's not working.
const activityEditableFields = async (z, bundle) => {
if (bundle.inputData.dueDate) {
(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}Z/.test(`${bundle.inputData.dueDate}`))
}
here duedate in the field and I am giving the format that if there is data in it then it should match the specified format but there's no difference in the zap. If you can help me as soon as possible. Do reply.
This shouldn't be necessary. Per the docs:
DateTime fields let users enter dates and times, using their human readable values, machine readable datetimes, or standard English words for time like tomorrow. Zapier interperpates the date input from users and outputs a standard ISO 8601 datetime to your API.
If you declare the field as a datetime, then bundle.inputData.dueDate will always be a proper ISO 8601 datetime.
The easiest way I could find to workaround this issue was to use with JS code only the first 10 characters of the ISO8601 Zapier date.
bundle.inputData.dueDate.substr(0,10)
or to use moment to parse date (This library is supported by Zapier):
const moment = z.require('moment');
....
moment(bundle.inputData.dueDate).format("YYYY-MM-DD HH:MM:SS UTC")
The only drawback is that you need to use the code editor

How to set entry filter for 24 hour time format in the listbox column in 4d database

I have a listbox with 2 columns (say "from time" and "to time"). I want to filter user input by 24 hour format only i.e. no other key should be allowed to press except 24 hour time format (i.e 00:00 to 24:00) in the cell. I tried with this: &"0-2"#&"0-3"#:& "0-5"#&"0-9"# it works well but it didn't allow to put something 19:22 or the value after 13:59 in the cell value as I haven't passed other optional value for that 24 hour time format. In regex, it's a bit easy to achieve this ('/^([01][0-9]|2[0-3]):([0-5][0-9])$/') but not sure how this can be done in the 4d database listbox cell field.
Any help would be appreciated. Thanks.
I suggest you make the list box columns text and manage the display and UI yourself if you require fine control over the input values.
The Time string method will convert a time value for you:
$timeStr:=Time string(Current time) // $timeStr = "07:23:45"
The input filters are not RegEx and will not give you the kind of fine control you need. They will let you filter unwanted characters (anything besides numbers for instance). Try this for the Entry Filter on the column
!0&9##:##:##
The result will be a text string of the numbers entered. Write a method to take the input string, parse the elements, validate them, update the data source and then return a properly formatted string for display. I would use the On data change form event as the trigger for running the method.
$h:=Num(Substring($inputStr;1;2))
$m:=Num(Substring($inputStr;3;2))
$s:=Num(Substring($inputStr;5;2))
Recent versions of 4D manage time values as seconds since midnight which is why you may get a longint value instead of a 'time' value sometimes. And depending on which version you are using and the type of listbox (collection, entity selection, array, etc.) you may not even have a 'time' type option for the list box column which can be confusing. Given all that it's just easier to stringify the value and work with that.
For example, what do you want to do if a user enters "33:45:00"? If you want to reject the "33" at the outset you can do this by evaluating each character as it is typed. The On After Keystroke form event lets you run your evaluation method after each change in the field and the Get edited text command allows you to see what the user is entering. https://doc.4d.com/4Dv18R3/4D/18-R3/Get-edited-text.301-4901376.en.html
To convert a string (or longint) into a time value use the Time method:
$timeVar:=Time($timeStr)
4D is a typed language and has had a time type since the beginning. However with the addition of ORDA some UI objects no longer support the time type (collection and entity selection list boxes, for example) and use a longint type instead. This can be confusing if you are working with an existing app or older code but attempting to use the newer tools. Be sure to look over
https://developer.4d.com/docs/en/Concepts/time.html
and
https://doc.4d.com/4Dv18/4D/18/Date-and-Time.201-4504355.en.html
You may not need to get so involved in the input. It depends on the nature of the UI and the data. Time and date is tricky in just about every platform.

In Freemarker Change output date format irrespective of input format

${(.vars["OCRResponse"].Date)?datetime("ANY RANDOM FORMAT")?string("mm-dd-yy").
Can we use If Else within ?datetime, or can we resolve this by using switch case?
If that date format is quite "random", and you need to do this a lot, then you are probably better of writing a freemarker.core.TemplateDateFormat+TemplateDateFormatFactory implementation, do the complex date parsing logic in Java, then register the factory as a "custom date format" (that's a FreeMarker configuration setting), let's say with name "random". Then you can do ${OCRResponse.Date?date.#random?string('MM-dd-yy')}. If you set the date_format configuration setting to MM-dd-yy, then you can even just write ${OCRResponse.Date?date.#random}.
You can find concrete examples of defining a custom formats here: https://freemarker.apache.org/docs/pgui_config_custom_formats.html
Another possibility is to use #if/#elseif/#else of course. If you need to do that on multiple places, then put your parser logic into a #function, where you #return the parsed date. So where you insert a date you just have something like ${parseRandom(OCRResponse.Date)} (here I have assumed that date_format is MM-dd-yy, otherwise add ?string('MM-dd-yy')).

Changing the timezone strings of date_lang.php

CodeIgniter stores timezones for its date class in
system/language/english/date_lang.php
I would like to change the strings in this file so that
$lang['UM12'] = '(UTC -12:00) Baker/Howland Island';
$lang['UM11'] = '(UTC -11:00) Samoa Time Zone, Niue';
would instead be
$lang['-12:00'] = '(UTC -12:00) Baker/Howland Island';
$lang['-11:00'] = '(UTC -11:00) Samoa Time Zone, Niue';
Is this possible at all?
Any change I make to the UM__ portion of one line makes it show as a blank on the dropdown. The remaining (unchanged) lines appear OK.
I have also tried to clone this file to application/language/english/ with similar bad results.
Any insights on this?
It looks like this would require hacks to the date_helper.php file which I am not willing to do.
Instead, the date class in CI has the timezones() function which allows you to convert from, for example, UM5 to -5. In that case one can wrap this function around the U__ value coming from the view/dropdown -- and then save it to DB as -5 or some other INT.
Since I want to show the user their selected timezone on that same dropdown, I am forced to have DB fields for the U__ and INT timezone formats. As far as I know, there is no CI function to convert from -5 to UM5.
So, for the user, I pull the U__ format into the view to autopopulate the dropdown.
For timezone conversions and such, I use the INT format.

Resources