Is there somewhere to get the source, read stats about it, et cetera,
without actually installing it via the gem command? RubyForge seems like
the only option, judging by a cursory search -- but a checkout doesn't
yield any actual source, and it's difficult to find useful information on
RubyForge.
···
On Wed, Apr 06, 2011 at 10:56:34PM +0900, Thomas Preymesser wrote:
Actually, I think mine just reached your first but everyone had
essentially the same suggestion. By the way, the suggestion about
subtracting from the 1st of the next month is perhaps smarter! That
way, you don't hv to worry about what the last day of the month is (31,
30, 28, 29?) I think it's really smart to just avoid all of that and go
back from the start of the next month!
OK. Now, I've got that last Sunday's date in January. And, I've now
delineated all of the successive Sundays thereafter. Each of them is a
budgetary fencepost for me. So, can someone help me to determine what
budget period, out of all 13 of them, that today's date, or any day for
that matter, would fall into? I think that all of my budget dates below
are actually strings, so, they don't parse with dates as they are.
Thanks,
Peter
Here's what I have now. It works. I just need to see what today, or any
day, would fall into.
require 'date'
now = DateTime.now
year = now.year
d = Date.new(now.year, 2, 1)
d.to_s
d -= 1
d.to_s
d -= d.wday
i = d.wday
d.to_s
firstbudgetfence = d
OK, I'm confused - is your budget fencepost the last Sunday or the Sunday every 4 weeks from the end of Jan?
Cheers,
Mohit.
9/26/2007 | 10:56 PM.
Peter Bailey wrote:
···
OK. Now, I've got that last Sunday's date in January. And, I've now delineated all of the successive Sundays thereafter. Each of them is a budgetary fencepost for me. So, can someone help me to determine what budget period, out of all 13 of them, that today's date, or any day for that matter, would fall into? I think that all of my budget dates below are actually strings, so, they don't parse with dates as they are.
Thanks,
Peter
Here's what I have now. It works. I just need to see what today, or any day, would fall into.
require 'date'
now = DateTime.now
year = now.year
d = Date.new(now.year, 2, 1)
d.to_s
d -= 1
d.to_s
d -= d.wday
i = d.wday
d.to_s
firstbudgetfence = d
now = DateTime.now
this_month = now.month
this_budget_fencepost = \\\ based on what we discussed earlier ///
then, you can find the budget fencepost for today using that..
If your budget posts are every 4 weeks from the last Sunday of January, you should be able to get the number of days since the first
num_of_days = this_budget_fencepost - first_fencepost
fencepost_number = num_of_days/ 28
You need to put in some check if the date is earlier than the first fencepost and check the numbers it actually produces, but roughly that should do it for you.
Cheers,
Mohit.
9/26/2007 | 10:59 PM.
Peter Bailey wrote:
···
OK. Now, I've got that last Sunday's date in January. And, I've now delineated all of the successive Sundays thereafter. Each of them is a budgetary fencepost for me. So, can someone help me to determine what budget period, out of all 13 of them, that today's date, or any day for that matter, would fall into? I think that all of my budget dates below are actually strings, so, they don't parse with dates as they are.
Thanks,
Peter
Here's what I have now. It works. I just need to see what today, or any day, would fall into.
require 'date'
now = DateTime.now
year = now.year
d = Date.new(now.year, 2, 1)
d.to_s
d -= 1
d.to_s
d -= d.wday
i = d.wday
d.to_s
firstbudgetfence = d
OK, I'm confused - is your budget fencepost the last Sunday or the
Sunday every 4 weeks from the end of Jan?
Cheers,
Mohit.
9/26/2007 | 10:56 PM.
It's a 28-day cycle, like a lunar cycle. The last Sunday in January is
the first fencepost, with the 1st budgetary period being from January 1
to that Sunday. Then, that Sunday is the first day of the 2nd budget
period, and so on.
But, I think I've got it now. My problem was my use of Time.now instead
of DateTime.now. DateTime.now allows me to compare these budgetary dates
with today's date. Thanks for everything.
now = DateTime.now
this_month = now.month
this_budget_fencepost = \\\ based on what we discussed earlier ///
then, you can find the budget fencepost for today using that..
If your budget posts are every 4 weeks from the last Sunday of January,
you should be able to get the number of days since the first
num_of_days = this_budget_fencepost - first_fencepost
fencepost_number = num_of_days/ 28
You need to put in some check if the date is earlier than the first
fencepost and check the numbers it actually produces, but roughly that
should do it for you.
Cheers,
Mohit.
9/26/2007 | 10:59 PM.
I basically just did a comparsion for the time.now between each of the
budget periods. If between 0 and 1, then budget1; if between 1 and 2,
then budget2, and so on. A little painful, but it's done with about 12
lines of code. I can live with that. Thanks.
now = DateTime.now
this_month = now.month
this_budget_fencepost = \\\ based on what we discussed earlier ///
then, you can find the budget fencepost for today using that..
If your budget posts are every 4 weeks from the last Sunday of January,
you should be able to get the number of days since the first
num_of_days = this_budget_fencepost - first_fencepost
fencepost_number = num_of_days/ 28
You need to put in some check if the date is earlier than the first
fencepost and check the numbers it actually produces, but roughly that
should do it for you.
Cheers,
Mohit.
9/26/2007 | 10:59 PM.
I basically just did a comparsion for the time.now between each of the budget periods. If between 0 and 1, then budget1; if between 1 and 2, then budget2, and so on. A little painful, but it's done with about 12 lines of code. I can live with that. Thanks.
Whatever works, I guess
I've always preferred a calculation to 12 comparisons. That way, it scales well when the periods change - you just need to change a division factor but like I said, whatever works for you!
By the way, are you calculating all 12 budget fenceposts every time you need to find out which one the current day falls in?
There are numerous optimizations possible...
* You could consider putting all the budget posts in an array and iterating over the array using a smaller loop code.
* You could check what month it is and check only the budget posts (month-1) and (month) and (month+1). If I'm not wrong, no more than 3 budget periods will fall in the same month - it's a bit convoluted though
* If you are in fact creating the budget fenceposts as you go along, you don't need to generate all 12.. just generate till you find the one you are looking for.
There are numerous optimizations possible...
* You could consider putting all the budget posts in an array and
iterating over the array using a smaller loop code.
* You could check what month it is and check only the budget posts
(month-1) and (month) and (month+1). If I'm not wrong, no more than 3
budget periods will fall in the same month - it's a bit convoluted
though
* If you are in fact creating the budget fenceposts as you go along, you
don't need to generate all 12.. just generate till you find the one you
are looking for.
Anyway, there are a few options - enjoy!
Cheers,
Mohit.
9/26/2007 | 11:38 PM.
Good suggestions all, Mohit. But, I just had to get this thing working
first, to get "the work out," so to speak. And, yes, when I have time, I
will look at what you suggest. Cheers.