Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
Zbych is currently offline  Zbych
Messages: 325
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 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

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 Smile 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 #38975 is a reply to message #38974] Fri, 01 February 2013 22:52 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
dolik.rce wrote on Fri, 01 February 2013 22:26

PS: I think the proper format for web apps is that which is simplest to use Smile 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...


Input fields like <input type="date"/>, <input type="datetime"/>, tags <time datetime="2013-02-01"></time> expect YYYY-MM-DDTHH:MM:SS.SSS+ZHZM format, that's why I think it should be default in skylark.
Re: Skylark and Date/Time format [message #39043 is a reply to message #38975] Sat, 09 February 2013 12:34 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
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 Smile

(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 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 325
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

Re: Skylark and Date/Time format [message #39053 is a reply to message #39052] Mon, 11 February 2013 14:11 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
Mirek, It appears that you forgot to update operator() in http class.

Line 93 in http.h:
	Http& operator()(const char *id, const char *v)   { var.GetAdd(id) = v; return *this; }
	Http& operator()(const char *id, const String& v) { var.GetAdd(id) = v; return *this; }
	Http& operator()(const char *id, const Value& v)  { var.GetAdd(id) = v; return *this; }


Re: Skylark and Date/Time format [message #39054 is a reply to message #39053] Mon, 11 February 2013 16:44 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Zbych wrote on Mon, 11 February 2013 08:11

Mirek, It appears that you forgot to update operator() in http class.

Line 93 in http.h:
	Http& operator()(const char *id, const char *v)   { var.GetAdd(id) = v; return *this; }
	Http& operator()(const char *id, const String& v) { var.GetAdd(id) = v; return *this; }
	Http& operator()(const char *id, const Value& v)  { var.GetAdd(id) = v; return *this; }





Ops, thanks, should be now fixed.
Previous Topic: question about overriding SqlError
Next Topic: How to call a C++ function in Witz template?
Goto Forum:
  


Current Time: Fri Mar 29 05:36:01 CET 2024

Total time taken to generate the page: 0.01478 seconds