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

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('...')

Related

How to re-execute the query script of an App Maker Datasource

Goal
Use App Maker to collect User Birthdays and display only the Birthdays this Month.
Issue
I have a data model, persons. In that model are two Datasources, the default persons and a second birthdaysThisMonth. The datasource query script in birthdaysThisMonth properly runs and returns only the birthdays this month from the persons model.
However, when I change a birthdate in the persons datasource, the birthdaysThisMonth datasource remains unchanged, e.g., the Query script in birthdaysThisMonth is not re-executed.
To change the birthdate, I select a new date from the date picker, and the new value is shown in a table. I am not using a submit button, I see the change when the date picker looses focus.
What I've Tried
This script is executed as a Query script in the birthdaysThisMonth datasource which is not set to Manual save mode. It returns the records I want.
function setBirthdays() {
var calcRecords = [];
var personsRecords = app.models.persons.newQuery().run();
for (i=0; i<personsRecords.length; i++) {
var id = app.models.persons.newQuery().filters.Id._equals = i;
if (personsRecords[i].birthdate.getMonth() == thisMonth()) {
var calcRecord = app.models.persons.newRecord();
calcRecord.emailSecondary = personsRecords[i].emailSecondary;
calcRecord.birthdate = personsRecords[I].birthdate;
calcRecord.Id = personsRecords[i].Id;
calcRecords.push(calcRecord);
}
}
return calcRecords;
}
Question
How do I re-execute the query script in birthdaysThisMonth when the data in persons has been updated. How do I trigger the query so it reevaluates the data in persons and filters accordingly.
Using Events and onAfterSave seems promising, but I haven't found an example of this.
BTW
I'd like this work to happen on the server side if possible.
See Markus Malessa's comment for the answer.
Unfortunately you can't use server events like onAfterSave to trigger reloading a datasource on the client, so your proposed solution won't work. It would seem that your only possible solution would be to make your persons datasource a manual save datasource, in the form where you change the birth date you will need a 'Save' button that calls widget.datasource.saveChanges() and in that function incorporate a callback that will reload your birthdaysThisMonth datasource
The way I'm attempting to push/pull data isn't great. Looks like Manual Mode provides the types of features I need.

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 !

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

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?

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);
}