Project

General

Profile

Feature #576

Argument types in callback function, Date()

Added by Imre Tokai over 11 years ago. Updated over 11 years ago.

Status:
Feedback
Priority:
Normal
Assignee:
-
Start date:
05/27/2012
Due date:
% Done:

90%

Estimated time:
Browser (if web client):

Description

Hi,

Collecting new Date() from client and it does come back but as a String and I'd need it as Date object because about to save it in DB column type DATETIME, timestamp with timezone Postgres. If new Date() is done again from received String it creates the saveable Date object BUT in server timezone's format and I'd need clients time zone instead exactly as generated and received.
Is there a way to receive pure @param {Date}, {JSDate}, {Object}...?
Or to create the object involving desired timezone that can be determined based on offset
Note: Javascript Date is just representation of number

https://www.servoy.com/forum/viewtopic.php?f=3&t=15293

Regards

History

#1

Updated by Patrick Talbot over 11 years ago

Why not return new Date().getTime() to the callback?
Then it's a long and you can convert it back on the server side to the correct Date.

You could also return an object like:

var date = new Date();
return {time: date.getTime(), offset: date.getTimezoneOffset()};

Unless I'm missing something?

#2

Updated by Imre Tokai over 11 years ago

Thanks Patrick,

So, need client's timezone and haven't found the proper javascript code to create new Date based on offset
Imre Tokai wrote:

If new Date() is done again from received String it creates the saveable Date object BUT in server timezone's

Any further idea?

Regards

#3

Updated by Patrick Talbot over 11 years ago

function onActionTime(event) {
    var js = "var date = new Date(); var time = date.getTime(); var offset = date.getTimezoneOffset();" 
    plugins.WebClientUtils.executeClientSideJS(js,callbackMethod,['time', 'offset']);
}

function callbackMethod(time, offset) {
    var hours = offset/100;
    var mins = offset%100;
    var millisOffset = (hours*60*60*1000) + (mins*60*1000);
    var date = new Date(parseInt(time) + millisOffset);
    application.output(date);
}

This gives me a date with UTC timeZone.
#4

Updated by Imre Tokai over 11 years ago

  • Status changed from New to Feedback
  • % Done changed from 0 to 90

Thanks Patrick,

Understand that Date() can be recreated on server but that's in UTC timeZone. Optimal would be to get original client's object, so that the Date is in client's timeZone and inserted to 1 DB column like that.
Implemented a work-around via 2 columns: one keeps the date and other the offset.

In general: it would be nice to have the ability to accept various types of object(s) from client, next to existing pure string(s)

Regards

Also available in: Atom PDF