Skip to content

format date columns issue partialy solved#9866

Open
ARMSTRONGOPONDO wants to merge 6 commits intoIDEMSInternational:masterfrom
ARMSTRONGOPONDO:format_date
Open

format date columns issue partialy solved#9866
ARMSTRONGOPONDO wants to merge 6 commits intoIDEMSInternational:masterfrom
ARMSTRONGOPONDO:format_date

Conversation

@ARMSTRONGOPONDO
Copy link
Collaborator

@Ag-Derek
@lilyclements
@rdstern
added a format tab radio button the new column and format description dialog #4282

@Ag-Derek
Copy link
Collaborator

Ag-Derek commented Jul 7, 2025

@ARMSTRONGOPONDO please remember to write the pull request as (fixes partly #4282) and for any other issues you will attempt in the future
Thank you

@lilyclements
Copy link
Contributor

@ARMSTRONGOPONDO great. Is this ready for review or are you still working on it?

@rdstern
Copy link
Collaborator

rdstern commented Jul 20, 2025

@ARMSTRONGOPONDO it is now 2 weeks since the @lilyclements question above. You have been silent and I wonder what you are working on, if not this?
So I decided to look:
a) Developer error which needs to be fixed, when loading the dialog.
b) Here is the current dialog:

image

So I tried typing into the receiver, but can't get Ok to be enabled. So I am unable to check if you have started on the R code.

This all seems remarkably little so far. Maybe it was 30 minutes of work?

Please let us know when you have made some progress and reply before then to say it is not yet ready for testing.

Copy link
Collaborator Author

@ARMSTRONGOPONDO ARMSTRONGOPONDO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request completely( fixes #4282 ) @Ag-Derek @lilyclements @rdstern

Screenshot 2025-07-23 084415 Screenshot 2025-07-23 084259

Copy link
Contributor

@lilyclements lilyclements left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ARMSTRONGOPONDO this is great! Really well done!! Working perfectly. The only changes are in the input text itself.

There are two small changes outlined below

@lilyclements
Copy link
Contributor

@ARMSTRONGOPONDO Nice one for adding it in
How is the HELP/? button done in the Make Date dialog? Can it be consistent with that?

@lilyclements
Copy link
Contributor

@ARMSTRONGOPONDO just had a look. Can you position it here instead:

image

Let me know when that's done. Otherwise this is looking great! nice job!

@ARMSTRONGOPONDO ARMSTRONGOPONDO self-assigned this Aug 4, 2025
@rdstern
Copy link
Collaborator

rdstern commented Aug 4, 2025

@ARMSTRONGOPONDO and @lilyclements, here are some suggestions:
a) Please can you add a control at the bottom to be able to choose the name of the new variable. This is in many dialogs, like the Transform dialog, see below:

image

It is the control at the bottom namely New Column Name, up to the Position button.

b) A smaller change, could you label your help button as R Help, and also mention it as R Help in the text below - so you say Click 'R Help' to see the full list
image

c) Could you delete - well move really - the examples section from here. That will makie that control neater, because it won't need the scroll bar:

image

d) Could you please add all those examples at the top of the pull down, shown in your current dialog above. You could include the brackets too, e.g. %b %-d (Jan 5), though only the first part, e.g. %b %-d will be transferred to the R function. Alternatively the Jan 5 could be displayed as a tooltip, when you hover over that entry? (I am suggesting they be added at the top, because I think they will be used more often than the single parts of the date you give now.)

@lilyclements
Copy link
Contributor

@ARMSTRONGOPONDO this is looking good. Are you able to work on @rdstern's suggestions?

@ARMSTRONGOPONDO
Copy link
Collaborator Author

Am currently working on it @lilyclements

@ARMSTRONGOPONDO
Copy link
Collaborator Author

I've implemented all the other requirements, but after implementing the new column name, I continue to receive this error. Could you suggest a way to solve it
@lilyclements
image

@lilyclements
Copy link
Contributor

lilyclements commented Aug 29, 2025

@ARMSTRONGOPONDO can you send up your most recent changes so I can have a look into this error? Looks like an issue in the R code so something for my end to fix :)

- Introduced `ucrFormatNew` control for specifying new column names in `dlgUseDate`.
- Updated help button text to "R Help" for clarity.
- Improved `ComboBoxnewformat` with specific date format examples and tooltips.
- Enhanced `TestOKEnabled` method to check `ucrFormatNew` completeness.
@ARMSTRONGOPONDO
Copy link
Collaborator Author

@lilyclements here are the implemented changes that ive pushed today ( I had a problem with my laptop)
image

This pull request introduces significant improvements to the date formatting functionality in the dlgUseDate dialog, enhancing both usability and flexibility for users. The changes add a new "format column" mode, allow users to construct custom date formats with helpful tooltips and examples, and provide direct access to R's date-time format help. Additionally, tooltips in the dlgPICSACrops dialog have been expanded for clarity.

Date Formatting Enhancements:

  • Added a new "format column" mode to dlgUseDate, allowing users to specify custom date formats and create new columns with formatted dates. This includes new radio buttons to toggle between using an existing column and formatting with a custom pattern, and updates to the logic that controls which UI elements are visible and which R parameters are set. [1] [2]
  • Populated the date format dropdown (ComboBoxnewformat) with common R date format patterns and individual format codes, and provided dynamic tooltips to guide users in selecting or constructing their own formats.
  • Added a help button (cmdHelp) that opens the R documentation for strptime, making it easier for users to find all available date-time format codes. [1] [2]
  • Updated the resource file (DlgUseDate.resx) to include a clear description of available date format codes for users.

Usability Improvements in Crop Dialog:

  • Expanded tooltips in the dlgPICSACrops dialog to include examples for entering comma-separated sequences, improving user understanding of input formats for planting dates, crop durations, and water amounts. [1] [2]

Copy link
Contributor

@lilyclements lilyclements left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ARMSTRONGOPONDO good news! You've done it - and you've done too much if anythign!

You are running, say:

format_date <- data_book$split_date(data_name="ghana", col_name="date", format_date=TRUE, format_string="%b %d", new_col_name="format_date", s_start_month=1)
data_book$add_columns_to_data(data_name="ghana", col_name="format_date", col_data=format_date, before=FALSE, adjacent_column="date")

But we just want to run:

data_book$split_date(data_name="ghana", col_name="date", format_date=TRUE, format_string="%b %d", new_col_name="format_date", s_start_month=1)

That is, we want to not have the assign to, and not to have the $add_columns_to_data.

I've outlined below how that can be achieved (my 1-6 points below).
I've also given other small bits and pieces to help improve this code.

Nice one!

Comment on lines +206 to +207


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because I'm picky, can you only have at most 1 empty line here (and elsewhere)

Comment on lines +233 to +240
'Save control
ucrFormatNew.SetSaveTypeAsColumn()
ucrFormatNew.SetDataFrameSelector(ucrSelectorUseDate.ucrAvailableDataFrames)
ucrFormatNew.SetLabelText("New Column Name:")
ucrFormatNew.SetIsComboBox()
ucrFormatNew.SetPrefix("format_date")
ucrFormatNew.setLinkedReceiver(ucrReceiverUseDate)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not want a save control. I can completely see why you would think we do. But, the thing is, the save control is too clever and automatically runs this line of data_book$add_columns_to_data.
But, we don't want to run that here.

Instead, can you:

  1. Remove the save control
  2. Add in a simple Label with the text "New Column Name:"
  3. Add in a ucrInput.
  4. The value of that ucrInput can be format_date by default
  5. That ucrInput is then the parameter value to the new_col_name parameter.
  6. This should only be visible when the rdoFormatColumn is checked.

So, to 3-5, for our ucrInput, to set this up, we would have like:

        ucrNEWINPUTNAME.SetParameter(New RParameter("new_col_name", 4))
        ucrNEWINPUTNAME.SetText("format_date")

To 6., we can make thing visible/invisible using .AddToLinkedControls.
For example, look in dlgTransformText. We run there:

        ucrPnlOperation.AddToLinkedControls(ucrInputSeparator, {rdoWords}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True)

This means that for ucrPnlOperation, when the panel is on rdoWords the ucrInputSeparator is made visible.
Can you see how? And can you see how we would/could then apply this to your case here using your ucrPnl, your rdoFormatColumns and your new ucrNEWINPUTNAME?

Comment on lines +291 to +312
Private Sub GroupBoxSettings()
If rdoUseColumn.Checked Then
Panelusemode.Visible = True
Panelformatmode.Visible = False
grpUseColumnnewfrm.Visible = False
grpfrmdescrp.Visible = False
clsDefaultFunction.AddParameter("format_date", "FALSE", iPosition:=4)
clsDefaultFunction.RemoveParameterByName("format_string")
clsDefaultFunction.RemoveParameterByName("new_col_name")
cmdHelp.Visible = False
ElseIf rdoFormatColumn.Checked Then
Panelusemode.Visible = False
Panelformatmode.Visible = True
grpUseColumnnewfrm.Visible = True
grpfrmdescrp.Visible = True
clsDefaultFunction.AddParameter("format_date", "TRUE", iPosition:=4)
If Not String.IsNullOrEmpty(ComboBoxnewformat.Text) Then
clsDefaultFunction.AddParameter("format_string", Chr(34) & ComboBoxnewformat.Text & Chr(34), iPosition:=5)
End If
clsDefaultFunction.AddParameter("new_col_name", Chr(34) & ucrFormatNew.GetText() & Chr(34), iPosition:=6)
cmdHelp.Visible = True
End If
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove some of this. So, we can remove our stuff that runs .AddParameter("format_date", ...) bits. See the next comment below.

Similarly, we can remove clsDefaultFunction.AddParameter("new_col_name", ... too by changing the set up to how it's outlined above

Comment on lines +203 to +204
ucrPnluseformat.AddRadioButton(rdoUseColumn)
ucrPnluseformat.AddRadioButton(rdoFormatColumn)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add/remove our format_date parameter, we can instead change the set up in our Initialise Dialog here.

So, we want to say in our Initialise that if you click on rdoUse, then we add format_date = FALSE, and if you click on rdoFormatColumns, our format_date = TRUE.

If we again look at dlgTransformText, we can see the line:

        ucrPnlOperation.AddToLinkedControls(ucrPnlPad, {rdoTrim}, bNewLinkedHideIfParameterMissing:=True)
        ucrPnlPad.AddRadioButton(rdoLeftPad)
        ucrPnlPad.AddRadioButton(rdoRightPad)

        ucrPnlPad.AddParameterValuesCondition(rdoLeftPad, "side", Chr(34) & "left" & Chr(34))
        ucrPnlPad.AddParameterValuesCondition(rdoRightPad, "side", Chr(34) & "right" & Chr(34))

This is very simple! It is simply saying, if you click on the rdoRightPad, add in side = "right" as a parameter value.
If you click on the rdoLeftPad, add in side = "left" as a parameter value.

So we would just want to have

        ucrPnluseformat.AddParameterValuesCondition(rdoUseColumn, "format_date", "FALSE")
        ucrPnluseformat.AddParameterValuesCondition(rdoFormatColumn, "format_date", "TRUE"`)

ucrBase.clsRsyntax.SetBaseRFunction(clsDefaultFunction)


ucrPnluseformat.SetRCode(clsDefaultFunction)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything with .SetRCode is always run in SetRCodeForControls sub. This should be removed from here

Comment on lines +293 to +294
Panelusemode.Visible = True
Panelformatmode.Visible = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of interest, what does this do?

End If


ucrPnluseformat.SetRCode(clsDefaultFunction, bReset:=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything with .SetRCode is always run in SetRCodeForControls sub. This should be removed from here

Comment on lines +391 to +392
If rdoUseColumn.Checked Then
End If
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be removed?

Comment on lines +397 to +398
If rdoFormatColumn.Checked Then
End If
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ANd this?

Comment on lines +402 to +404
Private Sub Controls_ControlValueChanged() Handles rdoUseColumn.CheckedChanged, rdoFormatColumn.CheckedChanged, ComboBoxnewformat.TextChanged, ucrReceiverUseDate.ControlContentsChanged
GroupBoxSettings()
End Sub
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this, you want to have .ControlContentsChanged for them all. So, instead of using rdoUseColumn or rdoFormatColumn, you should use the ucrPnl....

Whenever you have a ucr, it's very simply ControlContentsChanged, or ControlValueChanged - much simpler!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants