range

Check if a date within in range

只谈情不闲聊 提交于 2019-12-01 04:20:02
问题 I am trying to check if a date of format mm.dd.yyyy is greater than today and less than the date after 6 months from today. Here is my code: var isLinkExpiryDateWithinRange = function(value) { var monthfield = value.split('.')[0]; var dayfield = value.split('.')[1]; var yearfield = value.split('.')[2]; var inputDate = new Date(yearfield, monthfield - 1, dayfield); var today = new Date(); today = new Date(today.getFullYear(), today.getMonth(), today.getDate()); alert(inputDate > today);//alert

Ruby 'Range.last' does not give the last value. Why?

半世苍凉 提交于 2019-12-01 03:57:20
When using the triple dot notation in a ruby Range object, I get this: (0...5).each{|n| p n} 0 1 2 3 4 When I use the 'last' method I get: (0...5).last => 5 I would have expected 4 Is this is a bug? Or is there something I don't understand about the the concept of a Range object? This is by design. The Ruby 2.0 documentation is more specific : Note that with no arguments last will return the object that defines the end of the range even if exclude_end? is true . (10..20).last #=> 20 (10...20).last #=> 20 (10..20).last(3) #=> [18, 19, 20] (10...20).last(3) #=> [17, 18, 19] As Stefan has

scala Range for Long

北城以北 提交于 2019-12-01 03:54:06
问题 I'm new to the Scala language. I need Range for Long type. I need a List of [1, 2, 3 ... 10000000] with step 1. If I use until/to I get an error because of using Long instead of Int. I try to write simple function which expects a start, an end and and an empty List and generates a List of [start .. end]. Here is my function: def range_l(start : Long, end : Long, list : List[Long]) : List[Long] = { if (start == end){ val add_to_list = start :: list return add_to_list } else { val add_to_list =

Comparing NumPy arange and custom range function for producing ranges with decimal increments

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 03:40:58
Here's a custom function that allows stepping through decimal increments: def my_range(start, stop, step): i = start while i < stop: yield i i += step It works like this: out = list(my_range(0, 1, 0.1)) print(out) [0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6, 0.7, 0.7999999999999999, 0.8999999999999999, 0.9999999999999999] Now, there's nothing surprising about this. It's understandable this happens because of floating point inaccuracies and that 0.1 has no exact representation in memory. So, those precision errors are understandable. Take numpy on the other hand: import numpy as np out =

How to include end date in pandas date_range method?

纵然是瞬间 提交于 2019-12-01 03:32:56
From pd.date_range('2016-01', '2016-05', freq='M', ).strftime('%Y-%m') , the last month is 2016-04 , but I was expecting it to be 2016-05 . It seems to me this function is behaving like the range method, where the end parameter is not included in the returning array. Is there a way to get the end month included in the returning array, without processing the string for the end month? A way to do it without messing with figuring out month ends yourself. pd.date_range(*(pd.to_datetime(['2016-01', '2016-05']) + pd.offsets.MonthEnd()), freq='M') DatetimeIndex(['2016-01-31', '2016-02-29', '2016-03

How to set range between two thumbs in range seek bar in android?

依然范特西╮ 提交于 2019-12-01 03:26:24
问题 I am using the range seek bar in my app.It's working fine but my requirement is set the range between the two thumbs.In default both thumbs are overlapping each other in my case thumbs are not overlapping each other. How to set the range between the both thumbs in range seek bar? below is my range seek bar class.In my case difference between the two thumbs is 3.if two thumbs difference is 3,thumbs are can't overlap.how to set range between the thumbs? here is the class what i used public

Printing all contents EXCEPT matching range pattern using awk

▼魔方 西西 提交于 2019-12-01 03:10:08
问题 In Awk, the range pattern is not an expression, so canot use the "!" to not it. so how to implement it (Printing all contents EXCEPT matching range pattern using awk)? e.g. $cat 1.t abd hfdh # fafa deafa 123 # end the result I wanted: cat 1.t abd hfdh end EDIT: I gave an impertinent example. the endpattern should be different with the startpattern because I just have not test this. That's My fault. At the same time, I want to operate the range pattern and the not range pattern differently. So

Is there an elegant way to exclude the first value of a range?

核能气质少年 提交于 2019-12-01 02:58:16
Let's say I have a range from 0 to 10: range = 0...10 Three dots mean, that the last value (10) is excluded: range.include? 10 => false Now, is there a similar and elegant way to exclude the first value? For the above example, this would mean to include all values that are bigger ( > , not >= ) than 0 and smaller than 10. No. ((0+1)..10) I have two suggestions for you, they're not very ideal but they're the best I can think of. First you can define a new method on the Range class that does what you describe. It'd look like this: class Range def have?(x) if x == self.begin false else include?(x

Generate integer random numbers from range (0:10^12)

大兔子大兔子 提交于 2019-12-01 02:52:36
I want to generate 10000 integer random numbers between 0 and 10^12. Usually, the code would look like this: x <- sample(0:1000000000000,10000,replace=T) But I get following error message: Error in 0:1000000000000 : result would be too long a vector Is there a more memory efficient method that doesn't have to put 10^12 integers in a vector just to get a sample of size 10000? If not, is there a way to increase the max size of the vector? I'm working on a 64bit OS with 12GB of free RAM. PascalVKooten The real problem lies in the fact that you cannot store the sequence of 0:10^12 into memory. By

String, substring, Range, NSRange in Swift 4

99封情书 提交于 2019-12-01 02:44:26
I am using the following code to get a String substring from an NSRange : func substring(with nsrange: NSRange) -> String? { guard let range = Range.init(nsrange) else { return nil } let start = UTF16Index(range.lowerBound) let end = UTF16Index(range.upperBound) return String(utf16[start..<end]) } (via: https://mjtsai.com/blog/2016/12/19/nsregularexpression-and-swift/ ) When I compile with Swift 4 (Xcode 9b4), I get the following errors for the two lines that declare start and end : 'init' is unavailable 'init' was obsoleted in Swift 4.0 I am confused, since I am not using an init. How can I