Bootstrap datetime picker option to select from every half hour - bootstrap-datepicker

Is there a way to make bootstrap datetime picker to show me only options that represent intervals of half hour? (8:00; 8:30; 9:00; 9:30; ...)
Also I would like to know if there are ways to limit time intervals (say start from 8:00 AM until 18:00 PM).

You can set interval with the stepping parameter, while you can use enabledHours to limit valid hours of day. Assuming that "datetimepicker" is the id of your component, you can initialize it as follows:
$('#datetimepicker').datetimepicker({
stepping: 30,
enabledHours: [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
});
You can find further information in the official documentation of the library

For me it works:-
$('.datetimepicker').datetimepicker({
autoclose:true,
minuteStep: 30,
hoursDisabled: [19, 20, 21, 22, 23, 00, 1, 2, 3, 4, 5, 6, 7]
});

Related

Adding a number to a range of rows in a data frame (R)

I have a set of data (cumulative precipitation) that when the instrument resets, the starting level of the precipitation recorded changes. To correct this, I need to add the amount by which the the value dropped to the new recording so that the values are continuously increasing as they should.
i.e. the range of numbers below would be changed from:
26, 27, 28, 18, 19, 20
to:
26, 27, 28, 28, 29, 30
By adding the drop (10) to all values after the drop.
I think I need to loop the action through a range of cells (12746 to 17567)
You could do something like this:
# An example like yours, but with multiple drops.
vals = c(26, 27, 28, 18, 19, 20, 15, 17, 19);
correct_drops = function(vals)
{
n = length(vals);
# which() will get you indices where the condition holds true.
# Here it will get you the sites where 2 consecutive values
# have that the first value is greater than the second, meaning a drop.
indices_before_drop = which(vals[1:(n-1)] - vals[2:n] > 0);
# Looping through all drops, correcting each individually.
vals_corrected = vals;
for (ibd in indices_before_drop)
{
iad = ibd + 1;
drop = vals_corrected[ibd] - vals_corrected[iad];
vals_corrected = c(vals_corrected[1:ibd], (vals_corrected[iad:n] + drop));
}
return (vals_corrected);
}
vals_corrected = correct_drops(vals);
Of course there are special cases to be considered.
In any case I believe that which(..) and c(..) and subvector ranges v[a:b] are your friends here.

How to have a solid as well as dashed line in line chart highcharts

I am using line chart(highcharts) for my reactjs project and the requirement is data after 2015, line should be shown as dashed line and data before 2015 line should shown as solid line(no dashed). Is there any way out how to achieve this? I have check the highchart documentation there is property called as className inside series->data, but cannot understand how to do it? can anyone help me please?
Example you have 2 series. One series is data after 2015 at first index and data before 2015 at second index. And you need to add "dashStyle" is supported by highcharts.
The below example code will help you:
series: [
{
data: [1, 3, 2, 4, 5, 4, 6, 2, 3, 5, 6],
dashStyle: 'longdash'
},
{
data: [6, 7, 8, 9, 10, 11, 6, 2, 24, 5, 9],
dashStyle: 'solid' // or none dashStyle for 'solid' type
}
]
You can use the zones feature to reach wanted effect.
Demo: https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/series/color-zones-dashstyle-dot/
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
zoneAxis: 'x',
zones: [{
value: 8
}, {
dashStyle: 'dot'
}]
}]
API: https://api.highcharts.com/highcharts/series.line.zones.value

Handle DateTime overflow in JULIA

I know that Javascript Date() function can handle date entry overflows. But in Julia I get Error.
Is there any way to handle overflows automatically?
DateTime(2020, 4, 22, 15, 43, 67) # ----> 2020-4-22T15:44:07
DateTime(2020, 12, 31, 23, 59, 60) # ----> 2021-1-1T00:00:00
I find the default behavior of throwing an error useful. If you want to allow overflows you can define your own function for this eg. like this:
julia> MyDateTime(y, m, d, h, mi, s) =
+(DateTime(0), Year(y), Month(m-1), Day(d-1),
Hour(h), Minute(mi), Second(s))
MyDateTime (generic function with 1 method)
julia> MyDateTime(2020, 4, 22, 15, 43, 67) # ----> 2020-4-22T15:44:07
2020-04-22T15:44:07
julia> MyDateTime(2020, 12, 31, 23, 59, 60) # ----> 2021-1-1T00:00:00
2021-01-01T00:00:00
Note that the order of operations matters there - we first advance year, then month, etc. (as e.g. the effect of advancing time by one second may depend on the month, year and day):
julia> MyDateTime(2020, 2, 28, 23, 59, 60)
2020-02-29T00:00:00
julia> MyDateTime(2021, 2, 28, 23, 59, 60)
2021-03-01T00:00:00
(this can get especially tricky if you have very large and invalid values of month, day etc.)

Is this intended behavior or a bug in datetime timedelta?

from datetime import datetime timedelta
import pytz
ppt = pytz.timezone('US/Pacific')
first = ppt.localize(datetime(2013, 3, 10, 0, 0, 0))
first+=timedelta(hours=2)
first
returns datetime.datetime(2013, 3, 10, 2, 0, tzinfo=<DstTzInfo 'US/Pacific' PST-1 day, 16:00:00 STD>)
It should return datetime.datetime(2013, 3, 10, 3, 0, tzinfo=<DstTzInfo 'US/Pacific' PDT-1 day, 17:00:00 DST>)
You can workaround this, apparent, bug by doing astimezone(ppt) after adding the hours.
So, is this a bug? Am I doing it wrong? Or is it intended to have code refresh after adding time?
You need to call normalize() using the timezone object again when doing datetime arithmetic:
>>> first
datetime.datetime(2013, 3, 10, 2, 0, tzinfo=<DstTzInfo 'US/Pacific' PST-1 day, 16:00:00 STD>)
>>> ppt.normalize(first)
datetime.datetime(2013, 3, 10, 3, 0, tzinfo=<DstTzInfo 'US/Pacific' PDT-1 day, 17:00:00 DST>)
As noted in the docs:
In addition, if you perform date arithmetic on local times that cross DST boundaries, the result may be in an incorrect timezone. A normalize() method is provided to correct this.

What format are the timestamps returned by the LinkedIn API?

LinkedIn's API returns the following value:
[creationTimestamp] => 1407247548000
It looks similar to a UNIX timestamp, but there are three "extra" zeros at the end. What format is this in, and how can I decode it?
It is a timestamp in milliseconds. Handling this is language dependent. Some languages may expect a timestamp in milliseconds, while others may expect it in seconds. Python 3, for example, expects seconds, but also handles microseconds (1000 milliseconds).
from datetime import datetime
ts = 1407247548124
dt = datetime.utcfromtimestamp(ts / 1000)
print(dt) # datetime(2014, 8, 5, 14, 5, 48, 124000)
Python 2 doesn't handle milliseconds directly (it ignores the fractional part), so you need to split the milliseconds out separately.
from datetime import datetime
ts = 14072475481234
secs, millis = divmod(ts, 1000)
dt = datetime.utcfromtimestamp(secs).replace(microsecond=millis * 1000)
print(dt) # datetime(2014, 8, 5, 14, 5, 48, 124000)

Resources