Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
export class ServiceDates { // Reflects the "special" date ranges allowed in Service Dates. Namel, 1900 through 2099.
// There's probably a better naming convention, but this is a start
// Also, using patterns to match the special date range 1900..2099 is very hackish.
// Instead, start and end dates should be directly compared. Making this class obsolete.
private constructor() { }
// // A singleton object is a single object shared by all clients of the class.
// // That way you don't have multiple objects consuming memory.
// // Do we need a singleton? I'm not sure, but here's how.
// private static instance: ServiceDates;
// static get Instance() {
// if (this.instance === null || this.instance === undefined) {
// this.instance = new ServiceDates(); // there can be only one
// }
// return this.instance;
// }
// Use a name that suggests actual syntax: mm/dd/20yy or mm/dd/19yy
// for mm: /(0[1-9]|1[012])/ is short for /(01|02|03|04|05|06|07|08|09|10|11|12)/
// for dd: /(0[1-9]|[12]\d|3[01])/ is short for
// /(01|02|03|04|05|06|07|08|09)|(10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29)|(30|31))/
// Since /a/b/ is a syntax error: like regex '/a/' followed by 'b/'
// Use /a[/]b/ matches like 'a/b', or use /a\/b/ where \/ matches '/', in a string you need 'a\\/b' to match 'a/b'
// [/] is a) a more complex concept, b) harder to match than \/, so switch to \/
private static _date_MM_DD_19YYor20YY$ = /^(0[1-9]|1[012])\/(0[1-9]|[12]\d|3[01])\/(19|20)\d\d$/; // ^anchors$ match only entire string
private static _date_MM_DD_19YYor20YYOpt$ = /^((0[1-9]|1[012])\/(0[1-9]|[12]\d|3[01])\/(19|20)\d\d)?$/; // ^anchors$ match only entire string
private static _date_MM_DD_19YYor20YY = /(0[1-9]|1[012])\/(0[1-9]|[12]\d|3[01])\/(19|20)\d\d/; // un-anchored.
private static _date_MM_DD_19YYor20YYOpt = /((0[1-9]|1[012])\/(0[1-9]|[12]\d|3[01])[/](19|20)\d\d)?/; // un-anchored.
// Use a logical name that conveys intended usage
public static get date_Service$() { return this._date_MM_DD_19YYor20YY$; }
public static get date_ServiceOpt$() { return this._date_MM_DD_19YYor20YYOpt$; }
public static get date_Service() { return this._date_MM_DD_19YYor20YY; }
public static get date_ServiceOpt() { return this._date_MM_DD_19YYor20YYOpt; }
// As far as I know Typescript doesn't offer a way to combine "compiled" /patterns/.
// That is, you cannot form, an alternative, where ALT(/a/,/b/) = /a|b/
// But you can build a string pattern: alt = (a,b) => `(${a}|${b})`;
private static _date_MM_DD_19YYor20YY_String = '(0[1-9]|1[012])\\/(0[1-9]|[12]\\d|3[01])\\/(19|20)\\d\\d'; // use "\\"
public static get date_MM_DD_19YYor20YY_String() { return this._date_MM_DD_19YYor20YY_String; }
// I'm not sure these would be useful, so They are commented out until a valid use-case is found.
// But it still illustrates the difference with anchored and unanchored patterns.
// // For validators you normally must match the entire string, using the $ forms above
// // Here I have a looser version. In particular, Opt can match nothing at all anywhere in the string.
// private date_MM_DD_19YYor20YY = /(0[1-9]|1[012])\\/(0[1-9]|[12]\d|3[01])\\/(19|20)\d\d/; // ^anchors$ match only entire string
// private date_MM_DD_19YYor20YYOpt = /((0[1-9]|1[012])\\/(0[1-9]|[12]\d|3[01])\\/(19|20)\d\d)?/; // ^anchors$ match only entire string
// // Use a logical name that conveys intended usage
// public get date_Service() { return this.date_MM_DD_19YYor20YY; }
// public get date_ServiceOpt() { return this.date_MM_DD_19YYor20YYOpt; }
}