Formidable pro appointment field copy data value - javascript

I need to copy a appointment field (simply schedule appointments plugin) to other data Field, any people help tks
Reply from ssa:
This will mainly require using hooks from the Formidable Forms fields since those are what will be modified/updated. Then, the Appointment ID will need to be translated into the dates/times format needed.
We have an example of this here:
$appointment = new SSA_Appointment_Object( 123 );
// where 123 is the appointment ID database reference
$start_date = $appointment->start_date;
// date-time string like Y-m-d H:i:s (in UTC timezone)
$start_date = $appointment->start_date_datetime;
// DateTimeImmutable object (in UTC timezone)
copy appointment field to other data Field on formidable pro

Related

Convert date object to Firestore timestamp

I'm trying to convert a date object to a Firestore timestamp.
var dateOBJ = new Date();
var timeStamp = new firebase.firestore.Timestamp(dateOBJ);
This gives me an error:
Uncaught Error: Timestamp seconds out of range: Sun Dec 09 2018 11:37:05 GMT+0100
I tried converting the date object to seconds first by using .getTime() / 1000, but it's still out of range.
The timestamp is gonna be the expiration date for an url, so I need to add some time to it.
There are two ways of setting a date field in Cloud Firestore:
You specify a Date value for the field, in which case you fully determine what date is written.
You specify the firebase.firestore.FieldValue.serverTimestamp(), in which case the server writes the current date.
There is no way in the API to combine these two options, you either use one or the other.
Since you comment that you want to store the timestamp and an offset, that is also what I'd store:
a timestamp field that you let the server populate with firebase.firestore.FieldValue.serverTimestamp().
a offset field, that you populate from the app with the offset in days/hours.
That way you can reconstitute the effective expiration timestamp by combining the two fields.
You could even add a third field that stores the expiration timestamp, but that will require an extra write operation. I'd typically do this in Cloud Functions, to ensure you keep full control over the field and clients can't spoof it. If you don't do it in Cloud Functions, consider writing security rules that validate that the value if the calculated field is indeed the result of that calculation.
You won't get a consistent server side timestamp with a JavaScript date. Instead, send the server timestamp from the SDK:
const timestamp = firebase.firestore.FieldValue.serverTimestamp()
If you still want to set the timestamp as a Date you can just pass new Date() to Firestore and it will be saved as a timestamp.
Frank is right about setting timestamps into firestore.
If you want to check that timestamp on the front end afterwards you need to use .toDate on the timestamp object returned from firestore to turn it back into a JS date.

In the tcomb-form library, what date format will t.Date accept?

To set a value for a t.Date field, what format do I use?
value.my_date = '2018-07-12T14:31:40' // This doesn't work. Neither does any other format I try.
Note: I am not asking how to format a date for display. I need to populate my form fields with the previously saved values, but do not know how to format the date value in a way that t.Date will understand.
The format doesn't matter. The value must be set to a javascript Date instance. That instance can be set using any format javascript will accept. For example:
let string = 'Thu Jun 29 2018 15:12:27 GMT-0400'
value.my_date = new Date(string)

Issue with date and time is conversation depending on local timezone

Hello today I encountered an issue with time stamp conversions.. In my web form I'm using an bootstrap-datepicker where users can pick date and time. Afterwards I convert those values with moment.js to unix timestamp and pass it to PHP page. In the PHP page if the user is in different country the value is different and in the end in database is inserted wrong value.
So it's like the server timezone is Latvia/Riga GMT+2 and user from Georgia/Tbilisi has GTM+4. He's selecting start date 12.01.2017 15:00, Moment.js passes it to PHP page in the DB value of start date is inserted 12.01.2017 13:00.
Here is code from js
var start_date = $("#start_date").val();
var start_time = $("#start_time").val();
var start = moment.utc(start_date + ' ' + start_time, "DD.MM.YYYY HH:mm").tz("Europe/Riga");
afterwards var is passed via ajax to PHP script like start.unix()
In PHP it receives
$startDate = date('Y-m-d H:i:s', $_GET['start']);
And time is received by 2 hours earlier..
What can I do so the user selects time from anywhere on the world PHP inserts in DB as it selected correctly without timezone conversion.
You should never pass dates with timezones from client-to-server, always have the server be the boss in this case, otherwise you're inevitably going to have inconsistency issues in your database.
You either:
Always use UTC+0 dates.
Use keywords that represent a date (ie. yesterday, now, two days ago).
Using a keyword allows you to make the server decide which date do you want based on UTC+0 timezone.
TL;DR;
Always use UTC+0 datetimes and convert them server/client-side (it's your preference) depending on which timezone a user is on.
You can use following JS to get Client Timezone in JS:
var time_zone = Intl.DateTimeFormat().resolvedOptions().timeZone;
var start_date = $("#start_date").val();
var start_time = $("#start_time").val();
In PHP:
function getDateTime($start_date, $start_time, $time_zone) {
$dateTime = $start_date . ' ' . $start_time;
$date = new DateTime($dateTime, new DateTimeZone($time_zone));
$serverTimeZone = date_default_timezone_get();
$date->setTimezone(new DateTimeZone($serverTimeZone));
return $date->format('Y-m-d H:i:sP');
}
This might help you to sync timezone

EXTJS Ext.util.Format.date Automatic date conversion

I have a date field which contains data coming in from the database as 2015/07/31 13:01:53.180z.
Datetime is stored in UTC on database.
My code looks like this:
var startDateTime = Ext.util.Format.date(StartDateTime, 'm/d/y g:i:s A');
But the output I get is the conversion of UTC to IST(Indian).I checked on Chrome,Mozilla and IE.
I got same output all the time
Does ExtJs does this? Because I haven't wrriten any method for conversion.
I use ExtJs 4.1.1
I would appreciate any help on this.
Timezone is appended in the string->JS Date conversion.
To parse the date from database without timezone conversion you should use the Ext.Date.parse explicitly, not automatically through model field type 'date' or simply JS constructor new Date().
For example:
var db_date = '2015/07/31 13:01:53.180z',
js_date = Ext.Date.parse(db_date.substring(0,db_date.length-5), 'Y/m/d H:i:s'),
date_to_show = Ext.util.Format.date(js_date, 'm/d/y g:i:s A');
Obviously "substring" must be replaced by something better, for example you could format db date (cutting timezone part) in the web service serialization.
If you achieve to clean the date string in the web service you can also add "dateFormat" attribute to model fields to parse date correctly into models.

How can we retrieve Specific date format data from database through JavaScript?

I am working with Javascript and for some requirement I need to connect oracle database and retrieve some data.
How can i read timestamp values from oracle database in java script please provide me the method or any help.
i have checked my database and the format Is "YYYY-MM-DD HH:MM:SS,fffffffff"
How can i read this time stamp value.
Thanks
Lr
you could use oracle's datetime conversion when you select the data TO_CHAR( datetime, format )
like this you can get the datetime as a string from you db in any format you want and don't need to change the format later in Javascript.
see Oracle Format Models
simple example:
SELECT TO_CHAR( SYSDATE, 'MM/DD/YYYY HH24:MM:SS' ) AS TS FROM DUAL
or if you want only the time without date:
SELECT TO_CHAR( SYSDATE, 'HH24:MM:SS' ) AS TS FROM DUAL
If in JavaScript you get a timestamp, then just use
new Date(timestamp)
Cannot be done through JavaScript.
You need a webservice that outputs the required data in a specific format (preferably JSON) and use AJAX (http://api.jquery.com/category/ajax/) to fetch it.

Categories

Resources