From 4be88da5846b7ee826d65532bec4e8004bb0fa65 Mon Sep 17 00:00:00 2001
From: Rob <rob@synchro.net>
Date: Sat, 3 Oct 2020 12:51:25 -0700
Subject: [PATCH] Add user properties: birthyear, birthmonth, and birthday

These allow the easy reading or writing of these sub-field values of the
user.birthdate property. When migrating from the legacy formats (e.g. MM/DD/YY
or DD/MM/YY), it's required to write all 3 properties to get a correct
birthdate/age. Otherwise, "13/31/69" could become "19691/69" (for example)
which isn't going to parse correctly.
---
 src/sbbs3/js_user.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/src/sbbs3/js_user.c b/src/sbbs3/js_user.c
index 62b29719e4..48e6f9b25a 100644
--- a/src/sbbs3/js_user.c
+++ b/src/sbbs3/js_user.c
@@ -66,7 +66,10 @@ enum {
 	,USER_PROP_ZIPCODE
 	,USER_PROP_PASS
 	,USER_PROP_PHONE  	
-	,USER_PROP_BIRTH  
+	,USER_PROP_BIRTH
+	,USER_PROP_BIRTHYEAR
+	,USER_PROP_BIRTHMONTH
+	,USER_PROP_BIRTHDAY
 	,USER_PROP_AGE		/* READ ONLY */
 	,USER_PROP_MODEM     
 	,USER_PROP_LASTON	
@@ -209,6 +212,15 @@ static JSBool js_user_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
 		case USER_PROP_BIRTH:
 			s=p->user->birth;
 			break;
+		case USER_PROP_BIRTHYEAR:
+			val = getbirthyear(p->user->birth);
+			break;
+		case USER_PROP_BIRTHMONTH:
+			val = getbirthmonth(scfg, p->user->birth);
+			break;
+		case USER_PROP_BIRTHDAY:
+			val = getbirthday(scfg, p->user->birth);
+			break;
 		case USER_PROP_AGE:
 			val=getage(scfg,p->user->birth);
 			break;
@@ -506,6 +518,18 @@ static JSBool js_user_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict,
 			SAFECOPY(p->user->birth,str);
 			putuserrec(scfg,p->user->number,U_BIRTH,LEN_BIRTH,str);
 			break;
+		case USER_PROP_BIRTHYEAR:
+			SAFEPRINTF(tmp, "%04u", atoi(str));
+			putuserrec(scfg,p->user->number, U_BIRTH, 4, tmp);
+			break;
+		case USER_PROP_BIRTHMONTH:
+			SAFEPRINTF(tmp, "%02u", atoi(str));
+			putuserrec(scfg,p->user->number, U_BIRTH + 4, 2, tmp);
+			break;
+		case USER_PROP_BIRTHDAY:
+			SAFEPRINTF(tmp, "%02u", atoi(str));
+			putuserrec(scfg,p->user->number, U_BIRTH + 6, 2, tmp);
+			break;
 		case USER_PROP_MODEM:     
 			SAFECOPY(p->user->modem,str);
 			putuserrec(scfg,p->user->number,U_MODEM,LEN_MODEM,str);
@@ -754,6 +778,9 @@ static jsSyncPropertySpec js_user_properties[] = {
 	{	"zipcode"			,USER_PROP_ZIPCODE	 	,USER_PROP_FLAGS,		310},
 	{	"phone"				,USER_PROP_PHONE  	 	,USER_PROP_FLAGS,		310},
 	{	"birthdate"			,USER_PROP_BIRTH  	 	,USER_PROP_FLAGS,		310},
+	{	"birthyear"			,USER_PROP_BIRTHYEAR   	,USER_PROP_FLAGS,		31802},
+	{	"birthmonth"		,USER_PROP_BIRTHMONTH  	,USER_PROP_FLAGS,		31802},
+	{	"birthday"			,USER_PROP_BIRTHDAY  	,USER_PROP_FLAGS,		31802},
 	{	"age"				,USER_PROP_AGE			,USER_PROP_FLAGS|JSPROP_READONLY,		310},
 	{	"connection"		,USER_PROP_MODEM      	,USER_PROP_FLAGS,		310},
 	{	"modem"				,USER_PROP_MODEM      	,USER_PROP_FLAGS,		310},
@@ -795,7 +822,10 @@ static char* user_prop_desc[] = {
 	,"location (e.g. city, state)"
 	,"zip/postal code"
 	,"phone number"
-	,"birth date in either MM/DD/YY or DD/MM/YY format depending on system configuration"
+	,"birth date in 'YYYYMMDD' format or legacy format: 'MM/DD/YY' or 'DD/MM/YY', depending on system configuration"
+	,"birth year"
+	,"birth month (1-12)"
+	,"birth day of month (1-31)"
 	,"calculated age in years - <small>READ ONLY</small>"
 	,"connection type (protocol)"
 	,"AKA connection"
-- 
GitLab