date-range

c# check if a timespan range is between timespan range and how many hours

我们两清 提交于 2019-12-04 10:01:41
Assuming I have 3 time ranges: 07:00 - 18:00 18:00 - 23:00 23:00 - 07:00 and the code: public class TimeShift { public TimeSpan Start { get; set; } public TimeSpan End { get; set; } } List<TimeShift> shifts = new List<TimeShift>(); How can I check if every item in the list is between the 3 ranges above and how many hours? For example one TimeShift where: Start: 07:00 End: 23:30 then that means 16.5 hours. For the examples above: Range 1: 11 hours Range 2: 5 hours Range 3: 0.5 hours Here is a solution including tests: Calc public class TimeSpacCalculator { public static TimeSpan

Split the current month in to weeks in php

时间秒杀一切 提交于 2019-12-04 07:32:03
I want to split the current month in to weeks like first day to saturday and then sunday to next saturday.For ex: for May month, So i want to split that like 2016-05-01 to 2016-05-07 2016-05-08 to 2016-05-14 2016-05-15 to 2016-05-21 2016-05-22 to 2016-05-28 2016-05-29 to 2016-05-31 if i try the below code,i didnt get exact result. <?php $start_date = date('Y-m-d', strtotime('2016-06-01')); $end_date = date('Y-m-d', strtotime('2016-06-30')); $i=1; for($date = $start_date; $date <= $end_date; $date = date('Y-m-d', strtotime($date. ' + 7 days'))) { echo getWeekDates($date, $start_date, $end_date,

Doing range queries in Mongoose for Hour / Day / Month/ Year

北城以北 提交于 2019-12-04 07:09:55
Trying to figure out how to do this. Basically I want to sort by Hour / Day / Month / Year of my submissions. Each submission has a created field which contains a Mongoose Date object in the form of "created" : ISODate("2013-03-11T01:49:09.421Z") . Do I need to compare against this in the find() conditions? Here is my current query (I'm wrapping it in a count for pagination purposes FWIW so just ignore that part): getSubmissionCount({}, function(count) { // Sort by the range switch (range) { case 'today': range = now.getTime(); case 'week': range = now.getTime() - 7; case 'month': range = now

Ruby's range step method causes very slow execution?

我怕爱的太早我们不能终老 提交于 2019-12-04 05:57:30
I've got this block of code: date_counter = Time.mktime(2011,01,01,00,00,00,"+05:00") @weeks = Array.new (date_counter..Time.now).step(1.week) do |week| logger.debug "WEEK: " + week.inspect @weeks << week end Technically, the code works, outputting: Sat Jan 01 00:00:00 -0500 2011 Sat Jan 08 00:00:00 -0500 2011 Sat Jan 15 00:00:00 -0500 2011 etc. But the execution time is complete rubbish! It takes approximately four seconds to compute each week. Is there some grotesque inefficiency that I'm missing in this code? It seems straight-forward enough. I'm running Ruby 1.8.7 with Rails 3.0.3.

Efficiently find overlap of date-time ranges from 2 dataframes

徘徊边缘 提交于 2019-12-04 05:50:00
There are some questions out there regarding finding the overlap in date or time ranges ( for example ). I've used these to solve my problem, but I've ended up with an extremely slow (and not-at-all elegant) solution to my problem. I would really appreciate it if someone has an idea of how to make this faster (and more elegant): The Problem: I've got 2 dataframes, df1 and df2 , each with 2 columns that represent a start time and an end time: >>> df1 datetime_start datetime_end 0 2016-09-11 06:00:00 2016-09-11 06:30:00 1 2016-09-11 07:00:00 2016-09-11 07:30:00 2 2016-09-11 07:30:00 2016-09-11

PostgreSQL daterange not using index correctly

走远了吗. 提交于 2019-12-04 04:02:24
问题 I have a simple table which has a user_birthday field with a type of date (which can be NULL value) CREATE TABLE users ( user_id bigserial NOT NULL, user_email text NOT NULL, user_password text, user_first_name text NOT NULL, user_middle_name text, user_last_name text NOT NULL, user_birthday date, CONSTRAINT pk_users PRIMARY KEY (user_id) ) There's an index (btree) defined on that field, with the rule of NOT user_birthday IS NULL. CREATE INDEX ix_users_birthday ON users USING btree (user

PostgreSQL- Filter a date range

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 00:17:40
I'm a SQL developer and spend most of my time in MSSQL. I'm looking for a better way to filter a "Timestamp without timezone" field in a PostgreSQL DB. I'm using: Where DateField >= '2010-01-01' and DateField < '2012-01-01' But given that I'm not an expert at the syntax I have to think there's a better way. Any Suggestions? Thanks. Your solution is fine. If the dates are literals, I'd prefer, though: WHERE datefield >= '2010-01-01 00:00:00' AND datefield < '2012-01-01 00:00:00' This performs exactly the same, but is more maintenable, because it makes clear the point of each literal "date"

Average stock history table

北慕城南 提交于 2019-12-03 20:25:45
问题 I have a table that tracks changes in stocks through time for some stores and products. The value is the absolute stock, but we only insert a new row when a change in stock occurs. This design was to keep the table small, because it is expected to grow rapidly. This is an example schema and some test data: CREATE TABLE stocks ( id serial NOT NULL, store_id integer NOT NULL, product_id integer NOT NULL, date date NOT NULL, value integer NOT NULL, CONSTRAINT stocks_pkey PRIMARY KEY (id),

SQL group by frequency within a date range

老子叫甜甜 提交于 2019-12-03 19:32:34
问题 I have a requirement to write a stored procedure that accepts a start date, end date and a frequency (day, week, month, quarter, year) and outputs a result set based on those parameters. Obviously, the simple part is the query by date range, but how do you group by frequency? So if have a set of raw data like this: Date Count --------------------- 11/15/2011 6 12/16/2011 9 12/17/2011 2 12/18/2011 1 12/18/2011 4 And I call my stored proc like this: sp_Report '1/1/2011', '12/31/2011', 'week' I

Querying with nHibernate where todays date is between publishDate and Expiry date

假如想象 提交于 2019-12-03 12:52:35
I am trying to figure out how to best query in NHibernate so that the returned results are between for entries where todays time is >= PublishDateTime and <=ExpiryDateTime The expiry date can be null so I need to allow for that. I found a couple of examples here and here but they seem to work in a different way and accept 2 values and compare to one DB field. I want the other way wrong really. Query so far: var query = _session.CreateCriteria<Message>() .AddOrder(Order.Desc("PublishedDateTime")) .List<Message>(); return query; Any suggestions would be greatly received! Easiest Linq query: