date / time format

A place to discuss and receive support for the Web Auction application.

Postby auctions4you » Fri Jun 29, 2007 5:34 am

In The uk the date format is dd/mm/yyyy is there a way to change this in dataface?
Phil Stacey
auctions4you
 
Posts: 16
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Fri Jun 29, 2007 10:22 am

In general I have used yyyy-mm-dd throughout dataface because this is the format used by mysql. If you want to display a different format for a particular field, you can implement the %%fieldname%%__display() method.

See http://framework.weblite.ca/documentation/how-to/customize-date-format-in-delegate-class for an example.

-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Time format

Postby ADobkin » Mon Oct 29, 2007 8:58 am

Is it possible to do the same thing for a time field? I tried the following, but it didn't work:

Code: Select all
function time__default() {
       return date('H:i');
}


The data type on the field is just "time". In fields.ini, I have the following:

[time]
widget:type = time
widget:format = "H:i"
widget:starttime = "0:00"
widget:endtime = "23:59"
widget:interval = "1"

Also, is there a better way to enter a specific time like this without having a huge selection list of 1,440 (60x24) vales?

Thanks,
Alan
ADobkin
 
Posts: 195
Joined: Mon Oct 22, 2007 7:31 pm
Location: Atlanta, GA, USA

Postby shannah » Mon Oct 29, 2007 9:56 am

You could just use a text field widget instead:

Code: Select all
[timefield]
    widget:type=text


Then your default value method should work too.

To make your default value method work for the time widget you must make sure that the format matches that of the *values* in the time select list. (Look at the HTML source of the form, and find the ).

-steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby ADobkin » Mon Oct 29, 2007 4:18 pm

Okay, so for the time widget I described earlier, the values in the HTML are in the form H:i:s (hours:minutes:seconds). I was just missing the seconds before, since I only wanted my widget to display H:i format. However, it still isn't working for me. I now have:

Code: Select all
function time__default() {
         return date('H:i:s');
}


However, the time widget still defaults to 00:00. Note that I am using the date function to return the default value, since I didn't see a separate time function, and date has those parameters. Is that correct?

Another difference between the date and time widgets is that the date displays separate selection lists for day, month, and year, but the time widget displays hours and minutes together as one value in one large selection list. Maybe that's why the default isn't working....

Thanks,
Alan
ADobkin
 
Posts: 195
Joined: Mon Oct 22, 2007 7:31 pm
Location: Atlanta, GA, USA

Postby ADobkin » Mon Oct 29, 2007 4:27 pm

Maybe I solved my own problem here. Instead of using the time widget, I realized the date widget itself supports the time functions, so I switched it to widget:type = date. Now, the default function works, and I have the entry format I wanted originally! It now shows up in two selection lists, one for hours and a separate one for minutes.

So, that begs the question, what is the purpose of the time widget if the date widget already does everything?
ADobkin
 
Posts: 195
Joined: Mon Oct 22, 2007 7:31 pm
Location: Atlanta, GA, USA

Postby shannah » Mon Oct 29, 2007 4:47 pm

The time widget is still a little different. As you pointed out, it puts the times in one list rather than splitting them up over 2.

This is advantageous if there is a limited set of times that should be selectable.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Time Widget

Postby fezick » Thu Oct 16, 2008 6:58 pm

I have poured over the docs such as they are and can't seem to find a reference to this:

Is there a way to format time in 12 hour with am/pm declaration? I tried to sell the 24 hour clock and they just refuse to see the precision.
fezick
 
Posts: 4
Joined: Thu Oct 16, 2008 6:24 pm

Postby shannah » Fri Oct 17, 2008 8:24 am

Yes. To change the display of the the opening_time and closing_time fields, you can implement opening_time__display() and closing_time__display() methods in the tables/products/products.php delegate class.

Code: Select all
function opening_time__display(&$record){
    return date('Y-m-d g:i a', $record->strval('opening_time'));
}

function closing_time__display(&$record){
    return date('Y-m-d g:i a', $record->strval('closing_time'));
}
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby fezick » Fri Oct 17, 2008 8:51 am

Thank you... That is perfect.
fezick
 
Posts: 4
Joined: Thu Oct 16, 2008 6:24 pm

Postby shannah » Fri Oct 17, 2008 1:15 pm

Whoops there are problems with my code...

should be

[code]

function opening_time__display(&$record){
return date('Y-m-d g:i a', strtotime($record->strval('opening_time')));
}

function closing_time__display(&$record){
return date('Y-m-d g:i a', strtotime($record->strval('closing_time')));
}
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Refresher

Postby fezick » Wed Jul 15, 2009 3:44 pm

I let this issue drop last year as the client switched directions. Now I am playing with this for personal growth and can't seem to get that time to work.

Should I be using widget:type = time or widget:type = date with the above code. And should I be substituting the field name in there someone where? I just cant seem to make it go.

What I am trying to do is make a am/pm list of times starting at 8 am and ending at 6 pm and only list every 15 minute interval.

This is what my field entry looks like:

Code: Select all
[Start_Time_of_Presentation_Day_1]
widget:type = time
widget:format = "H:i"
widget:starttime = "8:00"
widget:endtime = "18:00"
widget:interval = "15"


and the function code:

Code: Select all
function Start_Time_of_Presentation_Day_1__display(&$record){
        return date('h:i a', strtotime($record->strval('Start_Time_of_Presentation_Day_1')));
}


Please help and thanks in advance.
Code: Select all
fezick
 
Posts: 4
Joined: Thu Oct 16, 2008 6:24 pm

Postby fezick » Wed Jul 15, 2009 3:56 pm

NEVER MIND. Hehe... you know some times all it takes is trying to explain the problem and you see the solution you have been missing the whole time.

Code: Select all
widget:format = "h:i a"


That little change and away I go. Thank you for your patience to my dumbness.
fezick
 
Posts: 4
Joined: Thu Oct 16, 2008 6:24 pm

Re: date / time format

Postby jvinolas » Wed Jan 19, 2011 2:35 am

HI everyone,

I have formatted the field with __display to match my timestamp format as dd/mm/yyyy, but the problem comes when I try to find a value with the included find form: the format with timestamp field is again mm/dd/yyyy and I don't know how to change that (without changing xataface code itself).

Is there any 'global' way to change date format in my app or mysql so it works also with the included find form?

Thanks.
jvinolas
 
Posts: 51
Joined: Thu Apr 15, 2010 12:31 am

Re: date / time format

Postby shannah » Fri Jan 21, 2011 12:02 pm

This is one area that could use some work. I'm not sure if there is a simple global way to change how Xataface handles dates for search. It may require some additional plumbing in Xataface to allow this.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Web Auction Discussion

Who is online

Users browsing this forum: Google [Bot] and 0 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved