Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Added DateTime data type support. #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion RemoteTK.component
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ if (remotetk.Client === undefined) {
escape: false
});
}

/*
*
* Helper function to ensure dates are properly formatted when using RemoteTK
* Per Apex docs: the specified string should use the standard date format “yyyy-MM-dd HH:mm:ss” in the local time zone.
*/
remotetk.Client.prototype.formatDateTime = function(jsDateObject) {
var output = jsDateObject.getFullYear() + '-';
if(jsDateObject.getMonth() + 1 < 10) output += '0';
output += jsDateObject.getMonth() + 1 + '-';
if(jsDateObject.getDate() < 10) output += '0';
output += jsDateObject.getDate() + ' ';
if(jsDateObject.getHours() < 10) output += '0';
output += jsDateObject.getHours() + ':';
if(jsDateObject.getMinutes() < 10) output += '0';
output += jsDateObject.getMinutes() + ':';
if(jsDateObject.getSeconds() < 10) output += '0';
output += jsDateObject.getSeconds();
return output;
}
}
</script>
</apex:component>
</apex:component>
5 changes: 4 additions & 1 deletion RemoteTKController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public class RemoteTKController {

if (valueType == Schema.DisplayType.Date) {
obj.put(key, Date.valueOf(svalue));
} else if (valueType == Schema.DisplayType.DateTime) {
// per apex docs: the specified string should use the standard date format “yyyy-MM-dd HH:mm:ss” in the local time zone.
obj.put(key, DateTime.valueOf(svalue));
} else if (valueType == Schema.DisplayType.Percent ||
valueType == Schema.DisplayType.Currency) {
obj.put(key, svalue == '' ? null : Decimal.valueOf(svalue));
Expand Down Expand Up @@ -291,4 +294,4 @@ public class RemoteTKController {

return JSON.serialize(result);
}
}
}