I'm using the strftime method of the Datetime class to output some info for logging purposes. It worked fine with the following formatting string in v1.0.13, but it now outputs garbage in v1.1.0. It seems to be related to the size of the internal buffer used for conversion, since reducing the size of the formatting string (and thus reducing the requested output) clears the problem up. Any ideas? A strftime input of "%m/%d/%Y %M" will not work properly but removing the space between %Y and %M does work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I presume you've solved your problem by now... Anyway I see that the buffer size is set to 64 and if that's not enough too bad! You need to (1) get the buffer with a new (2) check the return value of the strftime function and if it is the max, double the max, free the buffer and get a new one and try again until the return value shows that you've got everything there is to give or you consider that you've tried too often. The buffer can be defined static so that you can keep the biggest to avoid newing and deleting all the time. That's one way of doing it - there are perhaps others, like allowing a class variable to be set which allows programs to define what is the maximum size via some static method and throwing an exception if the buffer is too small. In so far as a strftime format can be anything (not just %m %Y etc) that is always going to be a possiblity.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm using the strftime method of the Datetime class to output some info for logging purposes. It worked fine with the following formatting string in v1.0.13, but it now outputs garbage in v1.1.0. It seems to be related to the size of the internal buffer used for conversion, since reducing the size of the formatting string (and thus reducing the requested output) clears the problem up. Any ideas? A strftime input of "%m/%d/%Y %M" will not work properly but removing the space between %Y and %M does work.
I presume you've solved your problem by now... Anyway I see that the buffer size is set to 64 and if that's not enough too bad! You need to (1) get the buffer with a new (2) check the return value of the strftime function and if it is the max, double the max, free the buffer and get a new one and try again until the return value shows that you've got everything there is to give or you consider that you've tried too often. The buffer can be defined static so that you can keep the biggest to avoid newing and deleting all the time. That's one way of doing it - there are perhaps others, like allowing a class variable to be set which allows programs to define what is the maximum size via some static method and throwing an exception if the buffer is too small. In so far as a strftime format can be anything (not just %m %Y etc) that is always going to be a possiblity.