Pickadate.js date picker - enable specific weekdays between two dates only - pickadate

Help required with Pickadate.js:
I'm attempting to enable Mondays to Saturdays (or other day combinations, e.g. Tuesdays and Thursday) within a certain date range (tomorrow until 14 days' time)
I'm sure this is achievable, but have drawn blanks thus far -
$('#test').pickadate({
disable: [
true,
//2,3,4,5,6,7,
{ from: [2016,5,16], to: 14 }
]
});
jsfiddle here:
http://jsfiddle.net/o7uweL0c/5/
if I uncomment the weekdays (2,3,4,5,6,7), and comment out the { from: [2016,5,16], to: 14 } - I get the right selection of days, but for any dates past or future. The two together don't seem to work.
Sure it's just a syntax thing - any help appreciated!

Worked this out today - in case anybody needs a pointer!
$('#test').pickadate({
min: true,
max: 14,
disable: [
1, 4, 7
]
});
http://jsfiddle.net/o7uweL0c/9/

Related

Count Days between Dates Swift (Considering what may be tomorrow.)

I have this code:
extension Date {
/// From today to self
/// - Returns: number of days.
func getDaysUntil() -> Int? {
return Calendar.current.dateComponents([.day], from: Date(), to: self).day
}
}
I need everything to be considered in terms of EST. So regardless of which time zone we are in, everything should be regarded as EST.
I am having a problem when comparing today with tomorrow.
So take the following case:
Date() // (now):: June 15.
self (compare to):: June 16.
Regardless the time of day today, I want to say that it's 1 day until the comparison date (self).
So, if it's 11:59pm and the comparison date (self) is 12:01am, I want the result to be 1 day. If it's 12:01am and the comparison date (self) is 11:59pm, I still want the comparison result to be 1.
As it is, no matter what I do, when we get to those extreme edges, the date calculation is off by 1, one way or the other.
Also, this isn't just a today vs. tomorrow issue. The correct count should be the result (considering the today/tomorrow conundrum) for any date.
Is there some fancy trick, or does anyone have any suggestion how we could accomplish this? Thanks!
If you need a default "don't care" time calendrical calculation what you need is to use noon time. Check WWDC session 227 Solutions to Common Date and Time Challenges. Check the "Midnight" part and what is said about why people should NOT use midnight.
extension Calendar {
static let iso8601 = Calendar(identifier: .iso8601)
}
extension Date {
/// From today's noon to self's noon
/// - Returns: number of days.
var daysFromToday: Int {
Calendar.iso8601.dateComponents([.day], from: Date().noon, to: noon).day!
}
/// Noon time
/// - Returns: same date at noon
var noon: Date {
Calendar.iso8601.date(bySettingHour: 12, minute: 0, second: 0, of: self)!
}
}
Usage:
let yesterday = DateComponents(calendar: .iso8601, year: 2022, month: 5, day: 2, hour: 23, minute: 59, second: 59).date!
yesterday.daysFromToday // -1

How to get last Sunday's date?

I need to show last Sunday's date in a cell for a weekly report that I'm creating on google sheets. I've been googling to find a solution and the closest I found is this:
=TODAY()+(7-WEEKDAY(TODAY(),3))
But this gives next Monday's date. Any idea how to modify this to show last Sunday's date? Alternately, do you have another way to solve this problem?
The formula you're looking for would be:
=DATE(YY, MM, DD) - (WEEKDAY(DATE(YY, MM, DD)) - 1) - 7
// OR
=TODAY() - (WEEKDAY(TODAY()) - 1) - 7
Depending on what you take to be "last Sunday," you can simplify/factor this:
If you take "last Sunday" to mean, "the Sunday which has most recently happened:"
=DATE(A2,B2,C2) - WEEKDAY(DATE(A2,B2,C2)) + 1
If you take "last Sunday" to mean, "the Sunday which took place during the previous week:"
=DATE(A4,B4,C4) - WEEKDAY(DATE(A4,B4,C4)) - 6
Working through it:
=TODAY() - (WEEKDAY(TODAY()) - 1) - 7
TODAY()
// get today's date, ie. 22/11/2019
WEEKDAY(TODAY())
// get the current day of the week, ie. 6 (friday)
-
// take the first date and subtract that to rewind through the week,
// ie. 16/11/2019 (last saturday, since saturday is 0)
- 1
// rewind back one less than the entire week
// ie. 17/11/2019 (this sunday)
- 7
// rewind back to the sunday before this
// sunday, ie. 10/11/2019
Hopefully this explanation explains what the numbers at the end are doing. + 1 takes you from the Saturday of last week to the Sunday of the current week (what I would call "this Sunday"), and - 6 takes you back through last week to what I would call "last Sunday."
See here:
try:
=ARRAYFORMULA(TO_DATE(FILTER(ROW(INDIRECT(VALUE(TODAY()-6)&":"&VALUE(TODAY()))),
TEXT(ROW(INDIRECT(VALUE(TODAY()-6)&":"&VALUE(TODAY()))), "ddd")="Sun")))
if today is Sunday and you want still the last Sunday then:
=ARRAYFORMULA(IF(TEXT(TODAY(), "ddd")="Sun", TODAY()-6,
TO_DATE(FILTER(ROW(INDIRECT(VALUE(TODAY()-6)&":"&VALUE(TODAY()))),
TEXT(ROW(INDIRECT(VALUE(TODAY()-6)&":"&VALUE(TODAY()))), "ddd")="Sun"))))
Using monday as 1 index, this will return the previous sunday or today if it is sunday
=if((7-WEEKDAY(today(),2))>0,today()-(7-(7-WEEKDAY(today(),2))),today()+(7-WEEKDAY(today(),2)))
One can select for other days of the week by changing the number "7" directly before "-WEEKDAY(today(),2)" in the three places that pattern exists.

ArangoDB Date Math - Month difference

Utilizing the DATE_SUBTRACT function in AQL, when handling dates near the end of the month, Arango seems to subtract 30 days instead of returning the actual previous month. e.g.:
for mo in 0..11
let month = date_subtract(date_now(),count,"month")
return month
returns
[
"2016-08-31T20:30:24.440Z",
"2016-07-31T20:30:24.441Z",
"2016-07-01T20:30:24.441Z",
"2016-05-31T20:30:24.441Z",
"2016-05-01T20:30:24.441Z",
"2016-03-31T20:30:24.441Z",
"2016-03-02T20:30:24.441Z",
"2016-01-31T20:30:24.441Z",
"2015-12-31T20:30:24.441Z",
"2015-12-01T20:30:24.441Z",
"2015-10-31T20:30:24.441Z",
"2015-10-01T20:30:24.441Z"
]
As you can see, this returns July twice, May twice, March twice, December twice, and October twice.
I actually just need the prior 12 months. The list I'd like is:
[
"2016-08-01T00:00:00.000Z",
"2016-07-01T00:00:00.000Z",
"2016-06-01T00:00:00.000Z",
"2016-05-01T00:00:00.000Z",
"2016-04-01T00:00:00.000Z",
"2016-03-01T00:00:00.000Z",
"2016-02-01T00:00:00.000Z",
"2016-01-01T00:00:00.000Z",
"2015-12-01T00:00:00.000Z",
"2015-11-01T00:00:00.000Z",
"2015-10-01T00:00:00.000Z",
"2015-09-01T00:00:00.000Z"
]
How in AQL could I ensure I always get the actual previous month instead of simply 30 days in the past? I fear that the date_subtract function won't handle leap years or 31sts.
It's hacky, but I managed to accomplish what I was after with this:
for mo in 0..11
return date_subtract(concat(left(date_iso8601(date_now()),7),'-01T00:00:00.000Z'), mo, "month")
Resulting in:
[
"2016-08-01T00:00:00.000Z",
"2016-07-01T00:00:00.000Z",
"2016-06-01T00:00:00.000Z",
"2016-05-01T00:00:00.000Z",
"2016-04-01T00:00:00.000Z",
"2016-03-01T00:00:00.000Z",
"2016-02-01T00:00:00.000Z",
"2016-01-01T00:00:00.000Z",
"2015-12-01T00:00:00.000Z",
"2015-11-01T00:00:00.000Z",
"2015-10-01T00:00:00.000Z",
"2015-09-01T00:00:00.000Z"
]
I would love a simpler solution to this, so please let me know if there is one. All those functions are a bunch of overhead.

nvd3 (d3.js) date format returns incorrect month

My data looks like this:
[{ x="2013-06-01", y=3}, { x="2013-07-01", y=7 }, { x="2013-08-01", y=3 }]
Chart x-axis is formatted as so:
chart.xAxis
.axisLabel('Date')
.tickFormat(function(d) { return d3.time.format('%b %Y')(new Date(d)); })
;
%b returns May, Jun, July respectively for the dates 2013-06-01, 2013-07-01, 2013-08-01
Why is it returning the previous month, and how can I fix it?
EDIT: If the date is formatted as 2013-06-02, it will return the correct month... does someone know what is happening to cause this?
#Amelia is correct it's because of timezone difference and because Date defaults to 24:00:00 if you don't specify a time. So, in case of EDT, which is -4:00, you lose 4 hours which puts you in the previous day (May 31 2013 20:00:00) and because the days in your dates are 01, this puts you in the previous month.
To bypass this you could append a time to your date if that is allowable in your case.
chart.xAxis
.axisLabel('Date')
.tickFormat(function(d) {
d = d.split('-')
// Create new date by using new Date(year, month, day, hour, second, ms)
// Subtracting 1 is necessary since Javascript months are 0 - 11.
return d3.time.format('%b %Y')(new Date(d[0], +d[1] - 1, d[2], 12, 0, 0));
});
Here is a working Fiddle

pickdate.js parameters and monthPicker

I'm trying to suit well this plugin pickadate.js v3.3.1 but I'm facing some difficulties.
First, I need to restrict selection of only future dates, 3 months from today's date. The docs didn't help me much so tried to do it this way. But it's not working.
Second, can I change this to a MONTH PICKER only? I need this for a Credit Card Expiry date field input.
The documentation isn't very great, But I guess being a new plugin I can use some good help of geeks here.
<script>
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+3;
$('#pickdate').pickadate({
// Escape any “rule” characters with an exclamation mark (!).
format: 'mmm dd , yyyy',
formatSubmit: 'yyyy/mm/dd',
hiddenPrefix: 'prefix__',
hiddenSuffix: '__suffix',
min: new Date(),
max: mm
//min: new Date(),
//max: (new Date() + 10)
})
$('#picktime').pickatime();
</script>
From the docs:
If dateMax or dateMin is an integer, it represents the relative number
of days till the min or max date.
I couldn't find any mentioning in the docs of a month picker. Why not use a standard dropdown ()?
What could prove to be of use to you with regards to range, again from the docs, is:
dateMin and dateMax can be either
an array representing a date ([ yyyy, mm, dd ])