'ts' Number Field in Database? (ex. 1428881039) - mysql

Thanks to outsourced development, each row in many of my tables has an undocumented field called ts with values such as 1428881039. This is in addition to an actual created_at timestamp field with values such as 2015-04-12 17:23:59 MDT.
These values are passed to this function before displaying it on the web page:
public static function display($ts, $created_at, $format = self::FORMAT_DETAILS){
if ($ts && Session::has('tz_offset')){
$adminTzOffset = Session::get('tz_offset');
$final = (int)$ts - (int)$adminTzOffset;
return date($format, $final);
}else{
return $created_at;
}
}
I understand that it has something to do with possibly making sure that the date shown is for the user's correct timezone, but it doesn't even seem to work; it ends up showing the wrong time. Obviously I could just display the created_at timestamp, but I understand what this is trying to do here.
Any ideas of what this ts field represents?

Based on the info garnered from the comments, I would say that the ts field is an attempt to record UTC time - since it appears it is 6 hours ahead of your created_at field.
The code itself looks like it is using this $ts value to calculate a corrected timezone based off a session variable. If you're getting incorrect times, maybe the logged in user has an incorrect timezone setup?

Related

Set Value of form field as current date in JHipster

We are trying to set default value of form field as current date in Jhipster.
Now, jhipster provides a moment format to a date which is eventually a ngbdatepicker. If we try to change the input type to "date" we cannot assign moment instance with date. If we typecast new date object as moment, the template shows error messages.
Please let us know if its possible.
Thanks in advance.
I have found a way around to solve this problem:
All you need to do is typecast your standard date object to moment after importing the moment obviously:
import * as moment from 'moment';
and typecast your field something like
your_form_field = moment(new Date());
Eg:
this.mstSite.siteUpdatedOn = moment(new Date());
Hope this solves your problems.
...Cheers...

How to work with input dates in a MySql / Laravel (5.6) / AngularJs application?

In my application, a user can specify a date in a form, via a datepicker. Doing so, the date has this format : "2018-05-16T12:45:30Z".
Then, I want to store it in a MySql database, in a TIMESTAMP column.
Later, the user can edit his data. Consequently, the datepicker has to be initialized with the date coming from the server, previously saved.
To manage this, I created an accessor and a mutator :
public function setDateNameInputAttribute($value)
{
$this->attributes['date_name_input'] = Carbon::createFromFormat('Y-m-d\TH:i:s\Z', $value);
}
public function getDateNameInputAttribute($value)
{
return Carbon::parse($value)->format('Y-m-d\TH:i:s\Z');
}
This code works fine : my front-end reads UTC (Zulu) dates and I can insert timestamps in my database.
However, it's not perfect.
Let's say I need for whatever reason to add one hour to a stored date
$myObject = MyClass::find(1);
$theDate = $myObject->dateNameInput;
Now $theDate is a "T Z format" string, because of the accessor. I could recreate a Carbon object to do my addition, but I think this Carbon -> string -> Carbon transition would be ugly. How can I make a nice operation ?
If my applications contains a lot of input dates, with many different model names, is there a way to generalize my accessor and my mutator ?
Actually, is my first approach good ?
Thanks for reading !

Couchbase document dates search - DateTime.Now()

I have a document in CB which has two dates, a start date and an end date. Let's say, a product's price discount. 10% off starting from today and ends next Friday. How can I get all the documents from CB which have a valid discount today?
I made a view and have the following in it:
var dt = new Date();
Which gets today's date. Then I can do a simple
if(doc.FromDate < dt && doc.ToDate > dt){ emit([ ..... ]);
This filters the documents how I want. But...
Question
Is this a good approach re view and index updating? Will the index update every day because the date changed? Just trying to understand the working of CB in this respect
What is the best approach for this type of searching? If not possible please tell me!
Cheers
Robin
Note: Please note, the question is NOT like this here or this here
Let's me clarify something here:
the map() function is used to create/update the index on disk, and this occurs just "after" the document is saved on disk. This is why using date.now() in the map reduce does not really makes sense.
So what you will do is to emit the date for example emit( dateToArray(doc.startDate) );
then when you query the view(index) you can use the startkey & endkey to do a range query.
&startkey=[2013,4,16]&endkey=[2013,4,24]
the index won't be updated just because system date changed, you have to update the document. also view indexer doesn't allow you to pass any arguments defined by user. in this case you should emit the data and use date as a part of the key to filter on view query. I guess the same behaviour for SQL indexes too. you cannot predict when exactly this document will indexed, in your example you are freezing timestamp when the doc has been indexed, it isn't even the time when it was changed

Joomla 2.5 Component - Store date/time, display on different timezones

Developing a component for Joomla v2.5, I'm using a table with a mysql timestamp column.
One of the component's settings is the "Timezone". I don't want to use server timezone, as code will run on different servers/timezones and I want to be indepedent. So the idea is to store timestamps in mysql, and display the correct date/time according to the component's parameter. The main drawback is the timezone that mysql server uses, that make the whole situation complicated. So, is there a way to store current timestamp in an universal format in MySQL and display it in the correct way?
The ultimate goal is for the component to be able to display the correct date/time based on the component's parameter, eg. user changes the parameter on the fly, no modification on the database take place, only on the "View"
In order to display the date in the correct timezone I use this:
JHtml::date($date_from_mysql , 'd/m/Y H:i:s', $my_component_timezone_parameter)
Please share your thoughts.
try
jimport ('joomla.utilities.date');
$date = new JDate($mydate);
$curdate = $date->toFormat('%Y-%m-%d %H:%M:%S');
for timezone settings
try http://docs.joomla.org/JDate::setTimezone/1.6
http://www.webamoeba.co.uk/site/index.php/articles-joomla-date-time
or try to override the store method in your table class:
public function store($updateNulls = false)
{
// get date
$date = JFactory::getDate();
// set variable for timestamp
$this->myDate = $date->toMySQL();
return parent::store($updateNulls);
}

Flex DateField and MySQL default date value 0000-00-00

I created a service and callResponder (Via Generate Service Call and Generate Form in Flash Builder 4) that query a MySQL database for a name and a birth date.
My problem is so simple I guess but I haven't been able to find the solution...
When I have an empty date in MySQL (0000-00-00), my binded DateField indicates 1899-11-30
I tried almost everything possible... A custom labelFunction, a custom function called straight after the call to my service to try to handle my data like this.. :
protected function parseDate(date:Date):void
{
if (date.getFullYear() == -1) {
friendbirthdate.selectedDate = null;
} else {
var df:DateFormatter = new DateFormatter;
df.formatString = 'YYYY-MM-DD';
friendbirthdate.selectedDate = date;
}
}
Unfortunately, this works only partially. When I try to update this same form in the database I get disconnected. I'm missing something here and would greatly appreciate a tip or two :-)
THANKS!
I recommend that you store NULL for unknown dates, as opposed to '0000-00-00'. NULL is a more accurate value in this case.
If you want to store it as NULL and display it as a different value you can do something like this:
SELECT COALESCE(date_column,'0000-00-00') as formatted_date
FROM your_table
Don't know if it will help somebody but I had trouble to insert values from a form, containing a DateField. That Form has been generated through the Flash Builder Generate Form tool.
The problem is that the service generated by Flash Builder expect a Date Object, no matter what... If you submit the form without selecting a date in the DateField, the service call crashes.
Let's have a look at a part of the generated sample service (Create and Update functions), we can see that PHP is expecting to transform a Date Object to a String like this :
mysqli_stmt_bind_param($stmt, 'sss', $item->friendname, $item->friendlastname, $item->friendbirth->toString('YYYY-MM-dd HH:mm:ss'));
First of all, be sure that your Date field in MySQL has as NULL default value.
Then alter the create and update functions like this :
if ($item->friendbirth == null)
$friendbirth = null;
else
$friendbirth = $item->friendbirth->toString('yyyy-MM-dd HH:mm:ss');
mysqli_stmt_bind_param($stmt, 'sss', $item->friendname, $item->friendnickname, $friendbirth);
This way, the service call script won't try to do kinda null->toString('...')