Data ranged subscribe strange behavior
d[5..<8]
returns Data.Slice
– which happens to be Data
. Generally, slices share the indices with their base collection, as documented in Slice
.
One possible reason for this design decision is that it guarantees that subscripting a slice is a O(1) operation (adding an offset for accessing the base collection is not necessarily O(1), e.g. not for strings.)
It is also convenient, as in this example to locate the text after the second occurrence of a character in a string:
let string = "abcdefgabcdefg"
// Find first occurrence of "d":
if let r1 = string.range(of: "d") {
// Find second occurrence of "d":
if let r2 = string[r1.upperBound...].range(of: "d") {
print(string[r2.upperBound...]) // efg
}
}
As a consequence, you must never assume that the indices of a collection are zero-based (unless documented, as for Array.startIndex
). Use startIndex
to get the first index, or first
to get the first element.
Strange behavior of range query in Elasticsearch
The default format for a date field in ES isstrict_date_optional_time||epoch_millis
. Since you haven't specified epoch_second
, your dates were incorrectly parsed (treated as millis since epoch). It's verifiable by running this script:
GET test_index/_search
{
"script_fields": {
"updated_pretty": {
"script": {
"lang": "painless",
"source": """
LocalDateTime.ofInstant(
Instant.ofEpochMilli(doc['updated'].value.millis),
ZoneId.of('Europe/Vienna')
).format(DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"))
"""
}
}
}
}
Quick fix: update your mapping as follows:
{
...
"updated":{
"type":"date",
"format":"epoch_second"
}
}
and reindex.
jQuery UI Slider using range, strange behavior
After a long investigation, it seems you can set values
or value
once it has been initialized !
So I've found no others solutions than doing this : http://jsfiddle.net/7YVVY/1/
It works, but it is not elegant :)
Weird behavior on clear dates
You should create a state to control the focusedRange
option.
const [focusedRange, setFocusedRange] = useState([0, 0]);
const handleClear = () => {
setState(initialDates);
setFocusedRange([0, 0]);
};
<DateRangePicker
focusedRange={focusedRange}
onRangeFocusChange={setFocusedRange}
...
When you select the startDate
, the DateRangePicker
internally sets the focusRange to [0,1]
. So you also need to reset that value when click on clear button. In this case for the default value [0,0]
.
You can check a little more about this information here.
Strange stacked range() loop behavior python
#!/usr/bin/env python3
(x,y) = 10,10
for X in range(x-1,x+2):
for Y in range(y-1,y+2):
print(X,Y)
The behaviour has to do with you re-assigning the y variable within your loop. Changing the variables assigned at for: to anything else has given me the behaviour you want:
9 9
9 10
9 11
10 9
10 10
10 11
11 9
11 10
11 11
Related Topics
Sort Dictionary Keys by Value, Then by Key
Disable Https Get Certificate Check in Swift 5
How to Rotate an Object Around Only One Axis in Realitykit
JSONencoder Won't Allow Type Encoded to Primitive Value
Encoding Swift String as Escaped Unicode
Correct Way to Use Nwconnection for Long-Running Tcp Socket
Operation Not Permitted When Executing 'Killall' with Swift
How to Open to a Specific View Using Home Quick Actions
How to Await X Seconds with Async Await Swift 5.5
Cannot Convert Value of Type 'Binding<String>' to Expected Argument Type 'Binding<String>'
Nscollectionviewitem Never Instantiate
Can You Enforce a Typealias in Swift
Error with Parse Query Findobjectsinbackgroundwithblock
Why Can't I Use Subscripting on a Ckrecord Object in Swift
Swift Error Using Initialized Properties in Expressions Before Super.Init
Passing a Variable Through a Segue? Xcode 8 Swift 3
How to Save a Custom Class as an Attribute of a Coredata Entity in Swift 3
Swift Protocol Property in Protocol - Candidate Has Non-Matching Type