Home » U++ Library support » U++ MT-multithreading and servers » Skylark and Date/Time format
Skylark and Date/Time format [message #38973] |
Fri, 01 February 2013 21:20  |
Zbych
Messages: 327 Registered: July 2009
|
Senior Member |
|
|
Hi,
I have a few questions regarding date/time formating in skylark.
When I try to set date scan and print format in main, all settings seem to be ignored.
I have to call SetDateFormat, SetDateScan, SetDateFilter in page handler to force my format.
What is correct way of setting locales in skylark application?
BTW Correct me if I am wrong but the only proper date format for web applications is YYYY-MM-DD and this should be default setting for skylark.
Second problem appears when I receive variable from http, want to modify it and send back to witz script, http keeps old value of variable.
For example:
int i = ScanInt(http["NUM"]);
i++;
http("NUM", i)("NUM2", i).RenderResult(MyApp/script.witz)
NUM keeps old value, NUM2 new value. Is it correct behavior?
Below is complete example:
#include <Skylark/Skylark.h>
using namespace Upp;
SKYLARK(HomePage, "")
{
// SetDateFormat("%1:04d-%2:02d-%3:02d");
// SetDateScan("ymd");
// SetDateFilter("A/\a .-");
Date d = ScanDate((String)http["ID"]);
RLOG(Format("Date befor scan: %s, after scan %`", http["ID"], d));
d = AddMonths(d, 1);
http
("ID", Format("%`", d))
("ID2", Format("%`", d))
.RenderResult("Skylark05/index");
}
struct MyApp : SkylarkApp {
MyApp() {
root = "myapp";
#ifdef _DEBUG
prefork = 0;
use_caching = false;
#endif
}
};
CONSOLE_APP_MAIN
{
SetDateFormat("%1:04d-%2:02d-%3:02d");
SetDateScan("ymd");
SetDateFilter("A/\a .-");
#ifdef _DEBUG
StdLogSetup(LOG_FILE|LOG_COUT);
Ini::skylark_log = true;
#endif
MyApp().Run();
}
index.witz:
<html>
<body>
<form action=$HomePage method="get" accept-charset="utf-8" enctype="multipart/form-data">
<P>
<INPUT type="date" name="ID" value="$ID">
<INPUT type="submit" value="Submit">
</P>
</form>
ID2 = $ID2
</body>
</html>
[Updated on: Fri, 01 February 2013 21:21] Report message to a moderator
|
|
|
Re: Skylark and Date/Time format [message #38974 is a reply to message #38973] |
Fri, 01 February 2013 22:26   |
|
Hi Zbych,
If I remember correctly, the date formatting and possibly other things are affected by the call to SetLanguage() for each request separately based on the __lang__ session variable. So that explains why you need to call SetDateScan() if you need some specific setting... Regarding the formatting for output, I prefer to use FormatDate with specific formatting string, it saves me from this problems.
The second problem has a simple reason: The operator() of Http does not replace the content of variable if it exists, it adds another variable of the same name. Only the first one is however used in the template. Perhaps it should use GetAdd() instead of simple Add() in this...
BTW: Try adding $set() to your template, it helps a lot with debugging situations like this.
Best regards,
Honza
PS: I think the proper format for web apps is that which is simplest to use In some cases a timestamp, in other cases YYYY-MM-DD or anything else that is simple to work with and that suits the clients side needs...
[Updated on: Fri, 01 February 2013 22:31] Report message to a moderator
|
|
|
|
Re: Skylark and Date/Time format [message #39043 is a reply to message #38975] |
Sat, 09 February 2013 12:34   |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
1. variable setting issue - this definitely is/was a problem, I have changed Add to GetAdd, should be fixed now.
2. The problem with Date/Time - I think that Zbych is basically right, OTOH we still also need to have LNG format for date (for regular text). I guess the solution is to provide one format as default (I think default should YYYY-MM-DDTHH:MM:SS) and second via function (e.g. Lng(date)). Quite easy to do, but I would like to have confirmation on this, so please comment 
(BTW, note that the set of witz funcions is easily extensible, so for now, if in hurry, you can resolve the issue by adding some function).
|
|
|
Re: Skylark and Date/Time format [message #39052 is a reply to message #39043] |
Mon, 11 February 2013 12:33   |
Zbych
Messages: 327 Registered: July 2009
|
Senior Member |
|
|
I tested latest changes (Add/GetAdd) and they don't work as intended. Old value is not replaced by new one. New value is simply added to the list. Test case from my first post returns following list:
ID VALUE
ID 2013-02-06
.__identity__
static myapp/static
.__lang__ 178867
.language en-us
ID 2013-03-06
ID2 2013-03-06
[Updated on: Mon, 11 February 2013 12:33] Report message to a moderator
|
|
|
|
|
Goto Forum:
Current Time: Sat May 10 09:05:59 CEST 2025
Total time taken to generate the page: 0.03786 seconds
|