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

Commit 69b581e

Browse files
committed
Added formatDateTime helper JS function
RemoteTK didn't seem to support datetime fields. Part of supporting them is sending the datetime value in the right format, which this function does per the Apex docs.
1 parent ff4319f commit 69b581e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

RemoteTK.component

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,26 @@ if (remotetk.Client === undefined) {
196196
escape: false
197197
});
198198
}
199+
200+
/*
201+
*
202+
* Helper function to ensure dates are properly formatted when using RemoteTK
203+
* Per Apex docs: the specified string should use the standard date format “yyyy-MM-dd HH:mm:ss” in the local time zone.
204+
*/
205+
remotetk.Client.prototype.formatDateTime = function(jsDateObject) {
206+
var output = jsDateObject.getFullYear() + '-';
207+
if(jsDateObject.getMonth() + 1 < 10) output += '0';
208+
output += jsDateObject.getMonth() + 1 + '-';
209+
if(jsDateObject.getDate() < 10) output += '0';
210+
output += jsDateObject.getDate() + ' ';
211+
if(jsDateObject.getHours() < 10) output += '0';
212+
output += jsDateObject.getHours() + ':';
213+
if(jsDateObject.getMinutes() < 10) output += '0';
214+
output += jsDateObject.getMinutes() + ':';
215+
if(jsDateObject.getSeconds() < 10) output += '0';
216+
output += jsDateObject.getSeconds();
217+
return output;
218+
}
199219
}
200220
</script>
201-
</apex:component>
221+
</apex:component>

0 commit comments

Comments
 (0)