<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
a) mktime() will return a (GMT based) unix timestamp, but assumes that
the params passed (namely, the 0 hour value) are local system time,
thus they will be converted to GMT first. the gmmktime() function
returns the same value format, but assumes that the params are already
in GMT, and will not do any further timezone shifting relative to local
system settings. You might want to play around with that function and
GMT params. NB: this is all at the PHP level, below the Drupal
application level. mktime() should work if your system's timezone
offset is set to what you expect. Is this hosted account somewhere or
a machine you control?<br>
roughly diagrammed:<br>
storage: mktime('local clock info') -> filters through local system
timezone offset -> GMT based unix timestamp<br>
storage: gmmktime('GMT clock info') -> GMT based unix timestamp<br>
display: GMT based unix timestamp -> format_date(...) -> 'local
clock info'<br>
<br>
b) storing dates is a design decision that you have to really evaluate
from the start. int's and unix timestamps are a reasonable approach
though. check out <a href="http://drupal.org/node/262066">http://drupal.org/node/262066</a>
& <a href="http://drupal.org/node/291799">http://drupal.org/node/291799</a>
for more info. The key with storing unix timestamps is to make sure
that everything is stored in the db in a uniform timezone offset
(ussually UTC). Understand how Drupal deals with timezone handling at
the application layer and don't try to "outsmart" it at the PHP layer.<br>
<br>
c) if all date's have been stored uniformly as unix timestamps:<br>
$month = format_date($node->data_assentament, 'custom', 'm');<br>
$day = format_date($node->data_assentament, 'custom', 'd');<br>
$year = format_date($node->data_assentament, 'custom', 'Y');<br>
<br>
The main idea here is that you have two layers of the application stack
(PHP and Drupal) both trying to be smart about timezone handling, and
each layer is undoing the other's efforts. You have to make one be
authoritative and the other passive from an application design
perspective. You will probably get the best results if you let Drupal
be the authoritative layer when it comes to timezones.<br>
<br>
Seth<br>
<br>
<br>
Lluís wrote:
<blockquote
cite="mid:45a29f450907170553o30ea6ebdn7417c9883a80c587@mail.gmail.com"
type="cite">
<pre wrap="">I have set timezone to UTC in admin/settings/date-time and no timezone for user.
So my problems are:
a) How do I have to store the date? is mktime(0,0,0,$month,$day,$year); correct?
b) If I want to use the date in views, how should I store it in
database? I use int(11) now
c) How can retrieve $month, $day, $year to make the form again?
On Fri, Jul 17, 2009 at 2:11 PM, Seth Freach<a class="moz-txt-link-rfc2396E" href="mailto:sfreach@gmail.com"><sfreach@gmail.com></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Lluís,
time() will return a value relative to the epoch, which is epicentered in
GMT.
date() takes that value and returns a local time based on it. IE, date()
knows about the computer's timezone and takes it into account.
Drupal's format_date() function uses gmdate() internally, which, unlike
date(), does not do local timezone offsetting. gmdate() returns the formated
date string in GMT. The reason format_date() does this is because it wants
to return a time that has meaning to the individual user's location, which
is not necessarily the computer's location, nor are all users always in the
same timezone. Drupal does the timezone offsetting itself to allow a system
default timezone and individual user configurable timezones too.
Double check your Drupal timezone settings at q=admin/settings/date-time and
possibly your user timezone settings at q=user/$uid/edit
Seth
Lluís wrote:
Making some research my problem is with format date:
$node->data_assentament -> 1247781600
date("d-m-Y H:i", $node->data_assentament) -> 17-07-2009 00:00
format_date($node->data_assentament,'medium') -> Dij, 07/16/2009 - 22:00
(I need the date in dd/mm/YYYY format)
Should I avoid format_date() or there is a better way to solve this?
On Thu, Jul 16, 2009 at 5:40 PM, Lluís<a class="moz-txt-link-rfc2396E" href="mailto:enboig@gmail.com"><enboig@gmail.com></a> wrote:
I have created a custom node type. I have a date field which I created
as int in order to use it in views, being able to sort it, format,
etc....
My problem right now is that when inserting a node with one date, it
appears as "day before" when viewing the node. How should I save it to
avoid this problem?
My form looks like
$arrayF=getdate(($node->data_paper>0 ? $node->data_paper : time()));
$arrayF['month']=$arrayF['mon'];
$arrayF['day']=$arrayF['mday'];
$form['data_paper_array'] = array(
'#type' => 'date',
'#title' => 'Data Factura',
'#default_value' => $arrayF,
'#required' => TRUE,
'#weight' => -9,
);
My insert query looks like
$dateF=$node->data_paper_array;
$factura_tmsp=mktime(0,0,0,$dateF['month'],$dateF['day'],$dateF['year']);//
$date['year']."-".$date['month']."-".$date['day'];
$node->data_paper=$factura_tmsp;
db_query("INSERT ......);
And my theme function:
$output.="<li><b>Data Factura:</b>
".format_date($node->data_paper,'small')."</li>";
Any hint/advice? Thanks
--
*La vida és com una taronja, què esperes a exprimir-la?
*Si creus que l'educació és cara, prova la ignorància.
*La vida és com una moneda, la pots gastar en el que vulguis però
només una vegada.
*Abans d'imprimir aquest missatge, pensa en el medi ambient.
</pre>
</blockquote>
<pre wrap=""><!---->
</pre>
</blockquote>
</body>
</html>