--- userpoints.module.orig	2011-12-30 17:41:37.000000000 -0600
+++ userpoints.module.new	2011-12-30 17:54:39.000000000 -0600
@@ -1874,3 +1874,46 @@
     'api' => 2.0,
   );
 }
+
+
+
+/**
+ * @param $uid User ID of the user to check points for, if omitted the currently logged-in user will be used
+ * @param $tid taxonomy id of the category to limit to, if omitted will use the "default" category (which may be "all")
+ * @param $period_begin The datetime of the beginning of the period to examine (UNIXTIME integer)
+ * @param $period_end The datetime of the end of the period to examine (UNIXTIME integer)
+ * NOTE: This function does NOT care if the points have since expired. We are only interested in the 
+ * total number of points GAINED during the specified time period.
+ * Other questions (which this function does NOT answer) might be:
+ *  - "what was the total point change (gain/loss) during this time period"
+ *  - "of the points gained during this time period, how many are still valid (unexpired)"
+ *
+ * @return number of points received in that user's account over the given time period
+ */
+function userpoints_get_points_gained_in_period($uid, $tid, $period_begin, $period_end) {
+	if (!$uid) {
+		global $user;
+		$uid = $user->uid;
+	}
+	if (!$tid) {
+		$tid = userpoints_get_default_tid();
+	}
+	
+	$query_sql = 'SELECT SUM(points) FROM {userpoints_txn} WHERE uid = %d';
+	$query_params = array($uid);
+	if ($tid) {
+		$query_sql .= ' AND tid = %d';
+		$query_params[] = $tid;
+	}
+	
+	// looking only at points gained
+	$query_sql .= ' AND points > 0';
+	
+	// points created during the specified time period
+	$query_sql .= ' AND time_stamp BETWEEN %d AND %d';
+	$query_params[] = $period_begin;
+	$query_params[] = $period_end;
+	
+	// NOTE: the (int) cast takes care of converting NULL to 0
+	return (int)db_result(db_query($query_sql, $query_params));
+}
