Was wondering if its possible (or maybe just not best practice) to return a calculated value from an EntityRepository method, or if I should be doing the calculation somewhere else. For example.
My Entity Users have Times (times are a Day of the week and a corresponding time for that day of the week not a hard date)
Looking to write a function that returns their NEXT time specific to the date, so for example if today is 2/8/16 (Monday) and the next "Time" is Tuesday at 12:00PM I want the function to simply return a DateTime object reflecting 2/9/16 12:00PM
Related
I am having problem constructing my query to find rows containing duplicated values specifically in ('day','time_from',''time_to').
The problem is that the value of 'day' column could be 1 or 2 combination(M or M-W)
The query should extract the following ('M-W','7:00','8:30') and ('M','7:00','8:30') as duplicate.
Is there any workarounds with these? Quite new to Laravel.
This my current query which can only extract if ('day') are exact value.
$dupeTeacher = DB::table('load_schedule')
->select('time_from', 'time_to', 'day')
->groupBy('time_from', 'time_to', 'day')
->havingRaw('COUNT(*) > 1');
$dupliTeacher=DB::table('load_schedule')
->select('load_schedule.*')
->joinSub($dupeTeacher, 'dupe_teacher', function ($join)
{
$join->on('load_schedule.day','=', 'dupe_Schedules.day');
$join->on('load_schedule.c_time','=', 'dupe_Schedules.time_from');
$join->on('load_schedule.c_time','=', 'dupe_Schedules.time_to');
})
->paginate(10);
I don't think you can do it as you're currently envisaging, as even if you could get it to see "M-W" as being a duplicate of either "M" or "W", it would not see it as a duplicate for "T". And two days of the week start with T...
You would be better, I think, storing the schedule entries in a separate table, using a relationship to tie it to a particular teacher. Each schedule entry would have a start time and an end time - when you populate it (however you populate it) if the schedule is for Monday 8:00 - 9:30 it just creates one entry in the schedule entries table. If the schedule is for Monday - Wednesday 8:00 - 9:30 then it creates three entries in the schedule entries table.
Ideally you would store these as datetime fields (ie. the actual date of the Monday / Tuesday / Wednesday in question, so a schedule entry for today would have a start time of 2021-12-08 08:00:00 and an end time of 2021-12 09:30:00 but if these are teachers, then it may be that it is "every Monday at 08:00:00" in which case your schedule entries table would have one column for the day of the week (as an integer, so 1 for Monday, 2 for Tuesday, etc.), one column for start time and one column for end time.
As it stands, you're going to be doing a lot of juggling to get it to work as you envisage - the above approach would simplify it considerably.
The current function in use in the JMeter script is
${__timeShift(dd/MM/yyyy,${__time(dd/MM/yyyy)},-P31D,,)}
to specify a review date 31 days ago.
I now learn that the project requires the review date to always fall on a Monday. Is there any way to make sure that performing a timeShift only selects a Monday?
I'm afraid __timeShift() function is not flexible enough, you can consider using __groovy() function instead and implement the following algorithm:
Get current date
Subtract 31 day
If current day of week is Monday - return the date in the past
Otherwise add 1 day until the date in the past becomes Monday
Example function code:
${__groovy(def now = new Date(); def monthAgo = now.minus(31); while (monthAgo[Calendar.DAY_OF_WEEK] != Calendar.MONDAY) { monthAgo = monthAgo.plus(1)}; return monthAgo.format('dd/MM/yyyy'),)}
Demo:
More information: Apache Groovy - Why and How You Should Use It
I use sub-queries to get hourly aggregated values for the last week for example: The number of http requests per hour over the whole last week, which will return 168 values in a range vector.
delta(http_server_requests_seconds_count[1h])[1w:1h]
Now I want to filter the value to return only the ones which are for a specific week day, lets say return only the 24 value from Monday.
I found some hints about day_of_week, timestamp, bool expr, but I cannot combine them to get it working or maybe it is not possible? Something like:
delta(http_server_requests_seconds_count[1h])[1w:1h] bool day_of_week() == 1
It'd be more effficient to adjust your start/end time to only over the day, but you could do:
(increase(http_server_requests_seconds_count[1h]) and on () day_of_week() == 1)[1w:1h]
I know there is a specified d3 time formatting. But when I check the example shown here d.Year = new Date(d.Year,0,1); the year's format is "1996"
Does it one of the other ways to format year as a string here, i don't quite understand it.
Also, if my time format is like"01/01/96", what is the right format to get the string here?
This isn't a d3 date formatting function. Its one of the basic forms of the Javascript Date constructor.
Specifically, it is using the multi-parameter form of the constructor:
new Date(year, month, day, hour, minute, second, millisecond);
except that all the time parameters are left as their default (0/midnight) values. If the original value for d.Year is the string "1996", the line
d.Year = new Date(d.Year,0,1);
creates a new Date object with year 1996 (the conversion from string to number will be automatic), month value zero (January), day value 1, and time midnight.
I'd like to only use the time for my model, to define when in the day the event is going to occur, but the only way I found was to do this:
#Temporal(TemporalType.TIME)
public Date end;
But I'd like to have in my database, a type TIME which is exactly what I'm looking for.
How can I do that?
You can use java.sql.Time, but be careful - it has other definition than MySQL TIME column type - it operates only in range 00:00:00 - 23:59:59 (although MySQL allows you to store intervals -/+ 838 hours)
model:
public Time end;
set with:
event.end = Time.valueOf("12:15:00");
Anyway maybe it's safer to store the time/interval as a string or integer (of minutes)?