From 0e5393f5326f108c099cedb092db9ea53023d76c Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Tue, 10 Nov 2009 22:53:56 +0000
Subject: [PATCH] Add an example usage of prototypes... When this code is
 load()ed, User objects get an extra birthDate property which is a JavaScript
 Date object representing the birthdate (rather than a string).

This adds the property to existing instances as well, so it doesn't need to
be loaded early.
---
 exec/load/birthdate.js | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 exec/load/birthdate.js

diff --git a/exec/load/birthdate.js b/exec/load/birthdate.js
new file mode 100644
index 0000000000..9c04b4c882
--- /dev/null
+++ b/exec/load/birthdate.js
@@ -0,0 +1,20 @@
+/*
+ * When this code is load()ed, User objects get an extra borthDate propert
+ * which is a JavaScript Date object representing the birthdate.
+ */
+
+User.prototype.birthDate getter=function() {
+	var mfirst=system.datestr(1728000).substr(0,2)=='01';
+	var match;
+	var m,d,y;
+
+	match=this.birthdate.match(/^([0-9]{2})[-/]([0-9]{2})[-/]([0-9]{2})$/);
+	if(match==null)
+		return undefined;
+	m=parseInt(match[mfirst?1:2],10)-1;
+	d=parseInt(match[mfirst?2:1],10);
+	y=parseInt(match[3],10)+1900;
+	if(this.age + y < (new Date()).getYear()-2)
+		y+=100;
+	return new Date(y,m,d);
+};
-- 
GitLab