Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I'm refactoring a method that should return 4-week periods. A period is calculated as the number of 4-weekly blocks in the current billing year. There are thirteen periods per billing year. First billing year began on 24/08/2008.
I have created a formula:
def period
period = (((self.utc.to_time - Time.new(2008,8,23,0,0,0,0)) / 60 / 60 / 24 / 7 / 52).modulo(1) * 13).ceil
period == 0 ? 13 : period
end
Over the years, it has become inaccurate, and we're now seeing a shift of a whole period: bookings in Period 1 are showing as Period 2. I tried re-calculating the formula with no success. I feel the formula is too complex anyway, and can probably be achieved more simply.
I would just use Date instead of Time and the calculation would be much easier.
DAYS_PER_PERIOD = 28
def period
days = Date.today - Date.new(2008, 8, 23)
periods = days / DAYS_PER_PERIOD
periods.to_i # would return a `Rational` instead of an `Integer` otherwise
end
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I want to get high of the first morning candle. highest(series, length) returns highest of last (length) numbers of candle. How can I get high of the first morning candle?
That could be achieved like that:
//#version=4
study("My Script", overlay=true)
dayStart = time('D')
dayStartHigh = 0.0
dayStartHigh := dayStartHigh[1]
// make sure it's a new day
if (dayStart[1] != dayStart)
dayStartHigh := high
plot(dayStartHigh)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
It is about the representation of time by using an int to store the number of seconds since January 1, 1970.
When will programs that use this representation face a time bomb? How should you proceed when that happens?
We are 2015 today. The number of seconds approximately since 1/1/1970 is
(2015 - 1970) * 365,25 * 24 * 60 * 60 = 1.420.092.000
That is the number of seconds in 45 years.
An unsigned int (32 bit) can store the value
4.294.967.295
which leaves us with
2.874.875.295 seconds ~ 90 years to go from now on
We still got some time to go.
In case a signed int is used, refer to this link (Thank you PM for the comment).
The signed int can store
2.147.483.647
which leaves us with
727.391.647 ~ 23 years to go from now on, i.e. 2038.
And thus the name of this problem: the Year 2038 problem
That is it can arise before our retirement.
For whatever you are concerned about, please refer to this link on SO.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
The system shall accept one measurement every second. The system shall present 6 real-time plots:
last minute
last hour
last day
last week
last month
last year.
For example, here is a beautiful yearly plot of the measurement presenting the average temperature for every month of the year(suppose the plot consists of 12 datapoints, connected with straight lines). When and how should I update it? The worst case is to re-calcucate the average temperature for each month at every measurement (once per second), then redraw the plot.
The plot of last minute we solve with a circular buffer - the new measurement is simply pushed to the deque eveyr second.
What about the other plots? How do we minimize the re-calculations for each one?
Solution
Keep averages of all vectors. Whe a new event happens, check which vectors to update (time % vector_sample_period). For the chosen vectors, ask the previous vector for it's average and push it in own circular buffer.
You minimize re-calculation by calculating only when needed. For example when you start over on the circular buffers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I have a java web application that has to deals with resource management.
FOr Example
Dept Min Max Resource Effective Date Last Date
HR 1 3 Alex 08/19/2013 12/31/2013
HR 1 3 Adam 08/19/2013 12/31/2013
IT 2 5 Jade 08/19/2013 10/31/2013
IT 2 5 Robert 11/01/2013 12/31/2013
IT 2 5 Lisa 08/19/2013 12/31/2013
I have different departments which has preset min/max employees I can allocate as a manager. So HR- dept has min of 1 and max of 3, I have allocated 2 from today to end of year.
In IT dept I have allocated a partial dates for Jade and robert to count them as 1 for entire period. Lisa for end-to end. which together is 2 which is in the min/max range.
Basically, the bottom line is at any point of time I have to make sure allocation will not violate the min/max rule. So, I want suggestions about how to validate these kind of scenarios in java application. Any open source API you found useful.
If I understood your question right, you basically want to find out which intervals overlap. Concerning dates, I normally tend to use http://joda-time.sourceforge.net/ since it has a very clean and nice API compared to out-of-the-box java Date.
Joda time also offers Intervals and a method to check if intervals overlap: http://joda-time.sourceforge.net/apidocs/org/joda/time/Interval.html#overlap(org.joda.time.ReadableInterval)
Nevertheless it didn't work for me as I wanted to check on a per-day basis, thus I had to implement it myself, using Joda time Intervals as base objects:
public static boolean checkInteraction(Interval one, Interval another) {
return ((one.getEnd().equals(another.getStart()) || one.getEnd().isAfter(another.getStart())) &&
(another.getEnd().isAfter(one.getStart()) || another.getEnd().equals(one.getStart())));
}
Having this in place, you can go through the intervals and check if they overlap/interact and check if it exceeds your max number.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Why is "Y" for "Year" capitalized while "m" for month is not? Moreover, "M" for minute is capitalized!
Time.now.strftime "%Y/%m/%d %H:%M:%S"
I always have difficulty to remember that as an english as second language programmer.
Methods of how to memorize the above formatting notation or explanation is much appreciated.
%Y is capitalized because it's long form year (2013). You can use %y and it will produce short form (13).
Also all parts in time section should be capitalized, because their lower-case variants are already taken by something else (in parentheses I provided current values).
`%h` - human short name for month (Jun)
`%H` - hour (14)
`%m` - month (06)
`%M` - minute (09)
`%s` - unixtime (1370599766)
`%S` - second
Simple, no?
If there's no rules, I will memorize it
Just memorize :)