|
|
Home » U++ Library support » LineEdit, EditFields, DocEdit » EditTime - how to change format?- [SOLVED]-EditField & Convert
EditTime - how to change format?- [SOLVED]-EditField & Convert [message #532] |
Sun, 08 January 2006 00:37 |
Garry
Messages: 7 Registered: November 2005
|
Promising Member |
|
|
Well the title pretty much describes my query.
When I enter a time into an EditTime widget and leave the field, the time entered is automatically formatted to include the date.
For example, I enter 8:00 and this automatically becomes "01/08/2006 08:00:00" which is more than enough information for my needs. Is there any way to change how this data is displayed?
Thanks,
Garry
[Updated on: Sun, 30 April 2006 17:17] by Moderator Report message to a moderator
|
|
|
|
|
|
Re: EditTime - Is it possible to change displayed format? [message #570 is a reply to message #567] |
Mon, 09 January 2006 23:26 |
Garry
Messages: 7 Registered: November 2005
|
Promising Member |
|
|
Thanks a million - it took me a while to figure out how to do it properly, but I've got it now. Certainly a great learning experience too. Now I realise how to make much better use out of Browser++ too!!
Anyway, here's my code now:
class MyTimeConvert: public ConvertTime {
public:
Value Format(const Value& q) const {
Time tm = q;
return ::Format("%02d:%02d", tm.hour, tm.minute); //ensures xx:xx format
}
int Filter(int chr) const {
if(IsDigit(chr) || chr == ':') //only accepts digits and ":"
return chr;
return 0;
}
};
typedef EditMinMax<Time, MyTimeConvert> EditTimeHM;
I only need Format to display hours and minutes with two digits for each unit.
This abridged version of Filter only allows digits and the colon symbol.
The standard version of Scan seems to work well at interpreting the time in this manner, but I might alter it in my own program so that invalid times are converted to proper times (eg 25:01 becomes 01:01).
By the way, now that I understand the actual processes behind this, I think there's a bug in ConvertTime. The global Format produces a String of Time with forward slashes "/" dividing days, months and years but ConvertTime::Scan and ConvertTime::Filter expect full stops instead ".". This causes EditTime to refuse to close once any time has been entered.
All the best, and thanks again!
Garry
*edit fixed a typo
[Updated on: Mon, 09 January 2006 23:27] Report message to a moderator
|
|
|
|
Re: EditTime - Is it possible to change displayed format? [message #36847 is a reply to message #570] |
Wed, 11 July 2012 18:57 |
lectus
Messages: 329 Registered: September 2006 Location: Brazil
|
Senior Member |
|
|
Garry wrote on Mon, 09 January 2006 17:26 |
Anyway, here's my code now:
|
Thanks to your code I managed to understand how to do validation for my own code.
I wanted the user to be able to only input time in the format hh:mm.
Here's the solution:
1) I put one EditString called "e" and one Button called "b" in the layout.
2) Add this code:
// Custom character filter
class MyTimeConvert: public Convert {
public:
int Filter(int chr) const {
if(IsDigit(chr) || chr == ':') //only accepts digits and ":"
return chr;
return 0;
}
};
// Validation callback. Uses regular expressions:
void MainWin::ValidateTime()
{
RegExp r0("\\d\\d:\\d\\d");
if (!r0.Match(~e))
Exclamation("Invalid time!");
}
e.MaxChars(5); // limit it to 5 chars
e.SetConvert(Single<MyTimeConvert>()); // sets custom filtering
b.WhenPush = THISBACK(ValidateTime); // when clicked check for format hh:mm.
|
|
|
Goto Forum:
Current Time: Fri Sep 20 10:09:53 CEST 2024
Total time taken to generate the page: 0.02589 seconds
|
|
|