Wiki has this to say about it:
There are certain considerations for the formation of sustained-release formulation:
If the active compound has a long half-life (over 6 hours), it is sustained on its own.
If the pharmacological activity of the active compound is not related to its blood levels, time releasing has no purpose.
If the absorption of the active compound involves an active transport, the development of a time-release product may be problematic.
Finally, if the active compound has a short half-life, it would require a large amount to maintain a prolonged effective dose. In this case, a broad therapeutic window is necessary to avoid toxicity; otherwise, the risk is unwarranted and another mode of administration would be recommended.
It was also mentioned that the substance "is embedded in a matrix of insoluble substance(s) (various: some acrylics, even chitin...)" or enclosed in "polymer-based tablets with a laser-drilled hole on one side and a porous membrane on the other side." Giant sultanas sound more appetising than any of those.
For melatonin, the half-life is short (about 45 minutes), the pharmacological activity is related to blood levels, absorption is passive and doesn't require an active transport mechanism and the theraputic window is about as large as it gets; melatonin is one of these things where you'd have to munch the pills like M&M's to reach a measurably toxic dose (somewhere upwards of 100mg/kg of bodyweight if you're a pregnant rat).
I tried injecting it into sultanas with a syringe and 0.8mm hypodermic needle, but the viscosity of the syrup was too high for the needle, and watering it down meant the viscosity was too low for it to remain in the sultana. The capsules also have a lot of filler in them, which tended to block the needle. Now I'm wondering about combining it with modelling plaster and forming it into pills that way. By playing around with the plaster mix, I might get the pills to disintegrate and release the melatonin at the right rate.