www.williamgibsonboard.com
www.williamgibsonboard.com
Random Thoughts
Basic computer assistance required, please.|
Go
![]() |
New
![]() |
Find
![]() |
Notify
![]() |
Tools
![]() |
Reply
![]() |
|
Member![]() |
If anyone has a clean trick to calculate a "30 days/end of the months" date with Java, I'm interested.
I'm working on a billing application, and I hate its guts. _____________________________ Albert's path is a strange and difficult one. |
|||
|
|
Member |
Now back in college we learned a mathematical formula that will compute leap years ... but I would try this:
GregorianCalendar calendar = new GregorianCalendar(); calendar.getActualMaximum(GregorianCalendar .MONTH); In the past, I also used to create an Calendar object, and catch the exception to do my validation. Not the most stylish thing to do, but lazy. ___________________________________________________________ "The best way to predict the future is to invent it." Alan Kay, 1971. |
|||
|
Member![]() |
This is how I ended up doing it :
We start with 'initialDate'. We want to calculate the expiration date, based on the X days/end of month rule. X can be 30, 60 or 90 The rule is : To obtain the final date, add the specified number of days, and go to the end of the month you obtain. Except if your inital date is on the 1st a month (then, one less month should be added).
Calendar cal = GregorianCalendar.getInstance();
cal.setTime(initialDate);
// add the number of months (30/30 , 60/30 or 90/30)
int monthsToAdd = daysToAdd / 30;
// use a second calendar
// (to check if we're on the first day of the month)
Calendar calTest = GregorianCalendar.getInstance();
calTest.setTime(initialDate);
calTest.set(Calendar.DAY_OF_MONTH, 1);
if ( calTest.compareTo(cal) == 0 ) {
// if the date is the first day of the month, then one less month should be added
monthsToAdd--;
}
cal.add(Calendar.MONTH, monthsToAdd);
// go to the end of the month
int nbDaysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
cal.set(Calendar.DAY_OF_MONTH, nbDaysInMonth);
cal.getTime() now gives the final date. _____________________________ Albert's path is a strange and difficult one. |
|||
|
Member![]() |
This is not basic computer assistance! It's asking us to do the job you are paid for! |
|||
|
Member![]() |
I don't see the problem here. What's wrong with that? |
|||
|
Member![]() |
I don't see any problem here either. There's nothing wrong with it. Community-based development is where it's at. _____________________________ Albert's path is a strange and difficult one. |
|||
|
Member![]() ![]() |
it's resource sharing. nothing wrong with that at all. |
|||
|
Member![]() ![]() |
See, if Arkan was really sneaky, he would have just started a code challenge thread with the above post as the initial problem challenge. Then he would have gotten back a larger set of possible solutions and could have Big O'd each one to find the one that worked best for his program....
*************************************************** * MEB_Registered: 20122002 |
|||
|
Member![]() |
Nothing "wrong" with that. But perhaps there should be a thread called "I'm a lazy bum. Can you solve this problem for me?"
PS. I'm kidding, guys. |
|||
|
Member![]() |
you must not work in software.
|
|||
|
Member![]() |
What does he get paid for? --- "Your enthusiasm for sporting events reveals nothing about the human condition except by way of irony." |
|||
|
Member![]() |
It could be charity work! |
|||
|
Member![]() |
Doesn't matter.
|
|||
|
Member![]() |
I mean in general. He makes billing applications in general? --- "Your enthusiasm for sporting events reveals nothing about the human condition except by way of irony." |
|||
|
Member![]() |
why does it matter?
|
|||
|
Member![]() |
It matters to me, and if it matters to me, it matters to the world!
--- "Your enthusiasm for sporting events reveals nothing about the human condition except by way of irony." |
|||
|
Member![]() |
Why does anything matter? |
|||
|
Member![]() |
Start a thread and find out.
|
|||
|
Member![]() ![]() |
anyone know any good data recovery tools? I put an old hard drive in an enclosure, hooked it up to my system over USB and it showed up fine on my Mac. it was already partitioned into three, and i moved some old data I'd like to keep onto two of them, and then attempted to erase the first partition, which was Fat32.
the intent was to change the format of that partition to the Apple OS extended but what happened was it reported failure and messed up the MBR or something because now none of the partitions are showing. i doubt it killed the data but i can'recall how to reset the part of the drive that stores the partition data stuff and google is spooling out endless streams of useless results for me at the moment..... *************************************************** * MEB_Registered: 20122002 |
|||
|
|
Member |
I believe Data Rescue II will entice you with the ability to see the names of the files they think they can recover, but not the actual data.
And pdisk is the Apple CLI partitioning tool, iirc. If all else fails, you might try partitioning them exactly the same sizes they were with no data in them and then recovering from the "empty" partitions, which hopefully still have all your data--just no directory record of it. But save that one for dead last for obvious reasons... |
|||
|
| Previous Topic | Next Topic | powered by eve community | Page 1 ... 70 71 72 73 74 75 76 ... 102 |
| Please Wait. Your request is being processed... |
|
www.williamgibsonboard.com
www.williamgibsonboard.com
Random Thoughts
Basic computer assistance required, please.