Issue with Daterangepicker - daterangepicker

I'm using the daterangepicker from https://sensortower.github.io/daterangepicker/docs#configuration
$(".daterangepicker-field").daterangepicker({
startDate:moment(),
endDate:moment(),
timeZone:'Europe/Bucharest',
forceUpdate: true,
orientation:'left',
ranges:{},
periods: ['day','week','month','year'],
expanded:true,
firstDayOfWeek: 0,
minDate:'2019-01-01',
callback: function(startDate, endDate, period){
var title = startDate.format('MMM D, YYYY') + ' – ' + endDate.format('MMM D, YYYY');
$(this).val(title);
}
});
The problem is, if I set the firstDayOfWeek: 1 (Monday), the calendar will change the label from Sunday to Monday, but in fact the days in the calendar will remain the same - so the calendar is wrong.
Can you help me figure out what is causing this?
Thanks!

I finally solve it, in case someone else needs it. The issue was related to moment.js.
I used the documentation found here:
https://momentjs.com/docs/#/customization/dow-doy/
with the following code:
moment.updateLocale("en", { week: {
dow: 1, // First day of week is Monday
}});

Related

How to calculate the number of time an event occurs in any month if I have the weekly schedule?

I am currently writing a flutter app which includes displaying the weekly schedule of a class. I also have to calculate the attendance of each student. To do that, I need the number of time each subject are taught in any given month and I am stumped as I can't think of a way to do that.
I have the weekly schedule of the class and I stored it in Firestore. It is formatted as below,
{Day: 1 , Major: 'EcE', Subject: 'Communication', Year: 5, Period: 1, ...}
Screenshot of a timetable entry
where Day refers to Monday, Tuesday, ...
It appears in the app like this.
My problem is, to track and calculate the attendance of students, I have to know how many times each subjects are taught in a month but I dont think multiplying said times in a week by 4 is viable since days in a month are dynamic. But I don't know how to work with a calendar programmatically so I am currently out of ideas. Any hints and suggestions are appreciated. The suggestions can be in either dart or node js since I can both implement in client side or cloud functions. Thanks a lot.
P.S - I haven't provide any code for now but please ask me for clarifications and I will provide the related codes. I just didn't want to bloat the post.
If I understood your question correctly all you need is to count the number of each weekday occurrence in a given month.
Here you go, in both js and dart:
JS:
var dtNow = new Date(); // replace this for the month/date of your choosing
var dtFirst = new Date(dtNow.getFullYear(), dtNow.getMonth(), 1); // first date in a month
var dtLast = new Date(dtNow.getFullYear(), dtNow.getMonth() + 1, 0); // last date in a month
// we need to keep track of weekday occurrence in a month, a map looks suitable for this
var dayOccurrence = {
"Monday" : 0,
"Tuesday" : 0,
"Wednesday" : 0,
"Thursday" : 0,
"Friday" : 0,
"Saturday" : 0,
"Sunday" : 0
}
var dtLoop = new Date(dtFirst); // temporary date, used for looping
while(dtLoop <= dtLast){
// getDay() method returns the day of the week, from 0(Sunday) to 6(Saturday)
switch(dtLoop.getDay()) {
case 0:
dayOccurrence.Sunday++; break;
case 1:
dayOccurrence.Monday++; break;
case 2:
dayOccurrence.Tuesday++; break;
case 3:
dayOccurrence.Wednesday++; break;
case 4:
dayOccurrence.Thursday++; break;
case 5:
dayOccurrence.Friday++; break;
case 6:
dayOccurrence.Saturday++; break;
default:
console.log("this should not happen");
}
dtLoop.setDate(dtLoop.getDate() + 1);
}
// log the results
var keys = Object.keys(dayOccurrence);
keys.forEach(key=>{
console.log(key + ' : ' + dayOccurrence[key]);
});
And here is the same thing in dart:
void main() {
DateTime dtNow = new DateTime.now(); // replace this for the month/date of your choosing
DateTime dtFirst = new DateTime(dtNow.year, dtNow.month, 1); // first date in a month
DateTime dtLast = new DateTime(dtNow.year, dtNow.month + 1, 0); // last date in a month
// we need to keep track of weekday occurrence in a month, a map looks suitable for this
Map<String, int> dayOccurrence = {
'Monday' : 0,
'Tuesday' : 0,
'Wednesday' : 0,
'Thursday' : 0,
'Friday' : 0,
'Saturday' : 0,
'Sunday' : 0
};
DateTime dtLoop = DateTime(dtFirst.year, dtFirst.month, dtFirst.day);
while(DateTime(dtLoop.year, dtLoop.month, dtLoop.day) != dtLast.add(new Duration(days: 1))){
// weekday is the day of the week, from 1(Monday) to 7(Sunday)
switch(dtLoop.weekday) {
case 1:
dayOccurrence['Monday']++; break;
case 2:
dayOccurrence['Tuesday']++; break;
case 3:
dayOccurrence['Wednesday']++; break;
case 4:
dayOccurrence['Thursday']++; break;
case 5:
dayOccurrence['Friday']++; break;
case 6:
dayOccurrence['Saturday']++; break;
case 7:
dayOccurrence['Sunday']++; break;
default:
print("this should not happen");
}
dtLoop = dtLoop.add(new Duration(days: 1));
}
// log the results
dayOccurrence.forEach((k,v) => print('$k : $v'));
}

Cypress: Extract text and number from variable

we have an element on our booking page ".ItineraryDate [datetime]:last" which displays the date of the last flight in the itinerary (e.g. Tue 7 Jul). For the purpose of a Cypress test, I need to extract the day (e.g. 7) and the month (e.g. Jul).
cy.get(".ItineraryDate [datetime]:last").then($span => {
const lastLegDate = $span.text()
})
This code creates const Tue 7 Jul, but I need to use only the day and the month. Do you know how could I extract it?
Cypress automatically includes moment.js and exposes it as Cypress.moment.
Refer moment formats
You can extract the month and day in anyway you want using Cypress.moment.
Markup:
<div class="date">Tue 7 Jul</div>
Test:
cy.get('.date').then(($el) => {
cy.log('original: ' + $el.text());
const dateString = Cypress.moment($el.text(), 'ddd D MMM')
const month = Cypress.moment(dateString, 'ddd D MMM').format('MMMM');
const day = Cypress.moment(dateString, 'ddd D MMM').format('D');
cy.log(`After formatting month = ${month}`);
cy.log(`After formatting day = ${day}`);
expect(month).to.equal('July');
expect(day).to.equal('7');
});
Screenshot:

date-fns MMMM formatting is broken in Russian locale

Lets assume we have the following date: 2019, 11, 1.
I want to display only the month's name, but MMMM formatting results into "ноября", when I expect to get "ноябрь".
It works OK in moment.js (locale: ru):
// if format starts with month name
moment([2019, 11, 1]).format('MMMM') => 'ноябрь'
// if format doesn't start with month name
moment([2019, 11, 1]).format('DD MMMM') => '1 ноября'
I would like to switch to moment.js, although I am already utilizing the library which strictly depends on date-fns. How can I achieve the format to show the month's name correctly in Russian language?
date-fns's GitHub repo
My workaround for this problem in use case for react-datepicker was to pass month name in cyrilic as format.
const getMonthName = (date) => {
const months = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'];
return months[date.getMonth()];
};
<DatePicker dateFormatCalendar={ getMonthName(new Date()) } />
format(new Date(2014, 1, 11), getMonthName(new Date(2014, 1, 11)))
Worked under my limited use case
You need to change MMMM to LLLL

Laravel carbon parse is giving incorrect output

I am working on chronic care health project in which i have to set future dates for patient injection. The doctor select start date for injection and then he select 3 days (i.e. Monday, Wednesday, Friday etc) which means patient will come 3 times a week.
The total injection are 20 that are divided by 3 times a week.
The problem that i am facing is that the parse function gives incorrect result if doctor select a day that matches today.
Lets suppose today is Wednesday and date is 2019-02-06 and doctor select 3 days that are:
Friday
Monday
Wednesday
Output should be:
- 2019-02-08
- 2019-02-11
- 2019-02-13
My code for controller:
if( $visitstart_date != null)
$startDate = Carbon::parse($visitstart_date);
else $startDate = Carbon::now();
if($perweek_visit1_day != '')
{ //Get date of selected day
$perweek_visit1_dayDate = $startDate->parse($perweek_visit1_day);
}
if($perweek_visit2_day != '')
{ //Get date of selected day
$perweek_visit2_dayDate = $startDate->parse($perweek_visit2_day);
}
if($perweek_visit3_day != '')
{ //Get date of selected day
$perweek_visit3_dayDate = $startDate->parse($perweek_visit3_day);
}
But when dump the 3 values it provide me :
2019-02-08
2019-02-11
2019-02-06 (incorrect)
For testing purpose I also parse the next visit date with each other like:
if( $visitstart_date != null)
$startDate = Carbon::parse($visitstart_date);
else $startDate = Carbon::now();
if($perweek_visit1_day != '')
{ //Get date of selected day
$perweek_visit1_dayDate = $startDate->parse($perweek_visit1_day);
}
if($perweek_visit2_day != '')
{ //Get date of selected day
$perweek_visit2_dayDate = $perweek_visit1_dayDate ->parse($perweek_visit2_day);
}
if($perweek_visit3_day != '')
{ //Get date of selected day
$perweek_visit3_dayDate = $perweek_visit2_dayDate ->parse($perweek_visit3_day);
}
but it again provided me the same output as :
- 2019-02-08
- 2019-02-11
- 2019-02-06
I don't know where i am going wrong, any support or help in this regard will be highly appreciated.
Thanks,

DateTime Ruby How to format correctly

My project is supposed to fetch specific values from multiple hashes a put those values in a text file. Ideally what I need my code to do is to have every date for the employees be seven days apart, so the text file would look something like this:
"Rachel Thorndike
2017-10-09-T04:29:46-05:00
Stacie Smith
2017-10-16-T04:29:46-05:00"
What this is supposed to do is fetch employee's names and put the time of their "handoff" on the line under them. I looked online and found the DateTime that Ruby features but it looks like whatever I do isn't working. My code is this:
require 'date'
jsonUser["users"].each do |user|
somefile.puts user["user"]["summary"]
print 'Handoff Date + Time: '
parsed = DateTime.strptime(jsonUser["start"], '%d-%m-%Y %H:%M')
utc = parsed.next_day(7).strftime('%d-%m-%Y %H:%M')
puts utc
end
But terminal returns this code with an error 'strptime': invalid date (ArgumentError). Would anybody help me get this code to work the way I want to? Anything that points me to the right direction? With explanations, if it isn't too much.
Thank you so much!
Update
I was able to get the iso8601 to appear under their name. My new code is
require 'date'
jsonUser["users"].each do |user|
somefile.puts user["user"]["summary"]
print 'Handoff Date + Time: '
parsed = DateTime.iso8601(jsonUser["start"])
utc = parsed.next_day(7).iso8601
somefile.puts utc
end
BUT the .next_day method isn't increasing by 7 days that I want too. Thought? I have only got one value that is appearing and that is going under every line. Its the value of jsonUser["start"] + 7 days...so `2017-
10-16T04:29:46-05:00`
This is what parse.next_day(7) gives me.
"Sr Chid
Handoff Date + Time: 2017-10-16T04:29:46-05:00
Ash A
Handoff Date + Time: 2017-10-16T04:29:46-05:00
Ven D
Handoff Date + Time: 2017-10-16T04:29:46-05:00
Abhi S
Handoff Date + Time: 2017-10-16T04:29:46-05:00"
The value of jsonUser["start"] is 2017-10-09T04:29:46-05:00 so the good thing is that it did increase by 7 but it only did it once.
Update for Amadan
require 'date'
date = DateTime.iso8601(jsonUser["start"])
jsonUser["users"].each do |user|
if user["user"]["self"] == nil
nil
else
somefile.puts user["user"]["summary"].gsub(/\w+/, &:capitalize).gsub(/[.]/, ' ')
somefile.print 'Handoff Date + Time: '
date = date.next_day(7)
somefile.puts date.iso8061
end
end

Resources