I had subclassed the Date object and written some Operator_Convert methods so that I could assign a date object from a string with just the = sign (and a couple other types)
In converting my code, I see that I have hundreds of places to change if I cannot figure out how to make this work.
In my subclassed object, I could parse the string and then set TotalSeconds based on another internal Date object created or setting individual items such as Year Month and Day.
So now my question is, can you change the datetime object (within a subclass) like you could in the date object. Or is the only way to “Change the date” is to assign it another datetime object outside of the object code.
You can “change the date” by making it a New Datetime object. Then, subclassing should also work but I would suggest to look at the functionality. There is a FromString method that you may want to take advantage of, instead of custom code.
Are these “convert from” or “convert to” versions of operator_convert ?
A convert from would be like
Operator_convert( fromValue as string)
These are basically a special form of Constructor so you dont actually return anything in any case
But you DO have a new instance that is uninitialized
Since datetime is immutable you may have difficulty altering this instance as even adding a date interval returns a new instance
I haven’t tried it, but I suppose you could change your class from being a subclass of datetime to it’s own type that holds a private property of type datetime and then pass through the properties and methods and such to that object. That should let you maniuplate the datetime property within an operator_convert() so you would only have to tweak your code in that one operator_convert method.
If that works, I’m sure it’s not best programming practice but it should address your problem.