const mongoconection =url;
const agenda = new Agenda({
db: {
address: mongoconection,
collection: "agendajobs",
option: { useUnifiedTopology: true }
}
});
new Promise(resolve=> agenda.once('ready', resolve));
agenda.define("say hello", job => {
console.log('hello');
});
(async function() {
await agenda.start();
await agenda.schedule(4/2/2020, 'say hello');
//repeat every
})();
how can I pass the dynamic date to the agenda?``
it's falling if I give in this formate 4/2/2020
If I give 5 minutes or even once a week if working
can anyone help me how to give time and specified date
Since schedule(when, name, [data]) as per the documentation
[s]chedules a job to run name once at a given time. when can be a Date or a String such as tomorrow at 5pm.
You need to provide a Date object instead of String.
The way to do it as per Date MDN documentation is new Date(2020, 1, 4) (assuming you meant February and not April) so your line could be:
agenda.schedule(new Date(2020, 1, 4), 'say hello');
Related
I want to create a chart. Using the library below.
https://charts.erik.cat/adding_datasets.html#database-eloquent-example-2
Query that dynamically reports the number of users for the last 6 months
(with month rows
Sample:
January = 1,
February = 2,
March = 3
...)
The output I want is:
$user_count_chart = [
"2" => 30,
"3" => 41,
"4" => 50,
"5" => 62,
"6" => 72,
"7" => 150,
];
**
key: month value
value: number of users
**
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('email')->unique();
$table->string('password');
$table->dateTime('email_verified_at')->nullable();
$table->rememberToken();
$table->timestamps();
});
return User::groupBy('date')
->orderBy('date', 'desc')
->take(6)
->get([
DB::raw('MONTH(created_at) as date'),
DB::raw('count(id) as total')
])
->pluck('total', 'date');
One important thing you may need to be careful is, missing months. Let's say if there isn't any user on march then your chart may not work as you expected. Please check this answer to overcome this "possible" problem.
Can use groupBy() function of Laravel Collection.
$user_count_chat = User::all()
->groupBy(function ($user) {
return $user->created_at->month;
})
->map(function ($group) {
return $group->count();
})
EDIT
Be carefull, I think month number is not good enough, Because 2019-Jan and 2020-Jan both has the same month number, but they are not the same, My advice is use 'year-month'
For this project i need for the week to start on monday opposed to sunday,
and the documentation of the vue component doesn't say if it's possible. Is there a way to modify it?
Thanks in advance
I managed it by extending the plugin and overwriting startMonthDay and startNextMonthDay computed properties to match monday as a starting weekday.
Code used below:
<script>
import VueRangedatePicker from 'vue-rangedate-picker';
export default{
name:'selector-fecha',
extends: VueRangedatePicker,
data: function(){
return{
}
},
computed: {
startMonthDay:function(){
return new Date(this.activeYearStart,this.activeMonthStart,0).getDay()
},
startNextMonthDay:function(){
return new Date(this.activeYearStart,this.startNextActiveMonth,0).getDay()
},
}
}
</script>
Thanks for your answers
It does not appear to a straight forward way to change the ordering of the calendar. I would go with a package like this that is more supported, more flexible and doesn't have a failing build.
Highlight example
<script>
var state = {
highlighted: {
to: new Date(2016, 0, 5), // Highlight all dates up to specific date
from: new Date(2016, 0, 26), // Highlight all dates after specific date
days: [6, 0], // Highlight Saturday's and Sunday's
daysOfMonth: [15, 20, 31], // Highlight 15th, 20th and 31st of each month
dates: [ // Highlight an array of dates
new Date(2016, 9, 16),
new Date(2016, 9, 17),
new Date(2016, 9, 18)
],
// a custom function that returns true of the date is highlighted
// this can be used for wiring you own logic to highlight a date if none
// of the above conditions serve your purpose
// this function should accept a date and return true if is highlighted
customPredictor: function(date) {
// highlights the date if it is a multiple of 4
if(date.getDate() % 4 == 0){
return true
}
},
includeDisabled: true // Highlight disabled dates
}
}
</script>
<datepicker :highlighted="state.highlighted"></datepicker>
I'm importing data from a Sybase database into ChartJS in VueJs2. I'm using the vue-chart module
I push the timestamps into an array as Unix times using
this.firstIn(new Date(tnaDetails[0].Sunday_FirstIn).getTime())
So:
[Sunday_FirstIn:2010-01-17 08:00:00.0]
Would convert to
1263708000000
Which I then add to the dataset:
datasets: [{
type: 'line',
label: "First In",
backgroundColor: "green",
data: this.firstIn,
fill: false
}
]
However, when the data is plotted on the graph, the values are changed. The above Unit Timestamp becomes
1263700000000
Which obviously returns the wrong time. I'm not doing anything to the ticks in the options.
Below is a result of the numbers being changed. The console has the original data:
Is there a setting that alters the precision/values of numbers in ChartJS that I'm not aware of?
Thanks.
Seth
For anyone who has any similar problem in future, I patched together a few solutions I found.
Firstly, from here Unix Timestamp in JavaScript, I wrote the method:
getTimeString: function(dateString) {
var hours = new Date(dateString).getHours();
var mins = new Date(dateString).getMinutes();
return Math.round((new Date("1970-02-01 " + hours + ":" + mins)).getTime());
}
The important part here is to make sure you have the same day. Not doing this will cause the ChartJS graph to plot the times in different places on the y-axis, even if the hours are the same.
Then from this StackOverFlow question and the related plunker, in the chart options, I have:
{
responsive: true,
maintainAspectRatio: false,
scales: {
yAxes: [{
position: 'left',
ticks: {
callback: value => {
let date = moment(value);
if (date.diff(moment('1970-02-01 23:59:59'), 'minutes') === 0) {
return null;
}
return date.format('H:mm');
},
stepSize: 3.6e+6
}
}]
}, //end scales
tooltips: {
callbacks: {
label: function(toolTipItem, data) {
let date = moment(toolTipItem.yLabel);
if (date.diff(moment('1970-02-01 23:59:59'), 'minutes') === 0) {
return null;
}
return date.format('H:mm');
}
}
}
}
Pay attention to the callbacks. They will format the time, calculating the difference from a set time to the time you need plotted. In the first function, you could really use any day, it wouldn't matter, as long as it's the same day. The stepSize will display hourly intervals on the yAxis.
I am using react-big-calendar. The events data has date start/end in epoch format. It doesn't render correctly. How can set the accessor properties to work with this JSON format?
actionItems =
[
{
"id": 3312,
"name": "Event Name",
"startDate": 1518415200000,
"endDate": 1519797600000,
"duration": "4 weeks",
},
]
my current calendar component declaration
<BigCalendar
events={actionItems}
views={allViews}
showMultiDayTimes
defaultDate={new Date()}
/>
You can use map function to get events in proper format
const mapToRBCFormat = e => Object.assign({}, e, {
start: new Date(e.startDate),
end: new Date(e.endDate))
})
<BigCalendar
events={actionItems.map(mapToRBCFormat)}
views={allViews}
showMultiDayTimes
defaultDate={new Date()}
/>
Epoch time is just a number and react big calendar accepts javascript data object. So you need to convert it into javascript date object using following.You can map function and use the object to render it and you need to multiply with 1000 to get time format. for more visit https://www.epochconverter.com/programming/#javascript
// availableSlots is your object.
var freeSlots = availableSlots.map(obj => {
var slotObj = {};
delete obj.duration;
slotObj['start'] = new Date(obj.start * 1000);
slotObj['end'] = new Date(obj.end * 1000);
slotObj['title'] = "Book"; // extra field
return slotObj;
});
Hope this works :)
I am trying to fully localize the alloyui scheduler in French.
Following this article: How can I get a localized version of a YUI 3 or AlloyUI component? the job is almost done.
However I am still missing tips for two things:
- I need the time format in the left column to be changed from 1-12am/pm to 1-24
- I don't succeed to localize the "All day" term in the left top corner (or at least a way to hide it).
Any help will be welcome
To change to a 24 hour clock, you need to set the isoTime attribute to true for each SchedulerView subclass that you are using.
To internationalize the strings, you need to set the strings attribute of Scheduler, SchedulerDayView SchedulerWeekView, SchedulerMonthView, SchedulerAgendaView, and SchedulerEventRecorder as well as setting YUI's lang attribute to the locale of your choice. For example, I've used Google Translate* to internationalize the Scheduler below for Spanish users:
YUI({lang: 'es-ES'}).use('aui-scheduler', function (Y) {
var es_ES_strings_allDay = { allDay: 'todo el dia' };
new Y.Scheduler({
render: true,
// https://alloyui.com/api/classes/A.Scheduler.html#attr_strings
// https://github.com/liferay/alloy-ui/blob/3.0.3-deprecated.65/src/aui-scheduler/js/aui-scheduler-base.js#L606-L622
strings: {
agenda: 'agenda',
day: 'día',
month: 'mes',
today: 'hoy',
week: 'semana',
year: 'año'
},
views: [
// https://alloyui.com/api/classes/A.SchedulerDayView.html#attr_strings
// https://github.com/liferay/alloy-ui/blob/3.0.3-deprecated.65/src/aui-scheduler/js/aui-scheduler-view-day.js#L363-L373
new Y.SchedulerDayView({
isoTime: true,
strings: es_ES_strings_allDay
}),
// https://alloyui.com/api/classes/A.SchedulerWeekView.html#attr_strings
// SchedulerWeekView extends SchedulerDayView: https://github.com/liferay/alloy-ui/blob/3.0.3-deprecated.65/src/aui-scheduler/js/aui-scheduler-view-week.js#L19
new Y.SchedulerWeekView({
isoTime: true,
strings: es_ES_strings_allDay
}),
// https://alloyui.com/api/classes/A.SchedulerMonthView.html#attr_strings
// https://github.com/liferay/alloy-ui/blob/3.0.3-deprecated.65/src/aui-scheduler/js/aui-scheduler-view-week.js#L19
new Y.SchedulerMonthView({
isoTime: true,
strings: {
showMore: 'mostrar {0} más',
close: 'cerrar'
}
}),
// https://alloyui.com/api/classes/A.SchedulerAgendaView.html#attr_strings
// https://github.com/liferay/alloy-ui/blob/3.0.3-deprecated.65/src/aui-scheduler/js/aui-scheduler-view-week.js#L19
new Y.SchedulerAgendaView({
isoTime: true,
strings: {
noEvents: 'No hay eventos futuros'
}
})
],
// https://alloyui.com/api/classes/A.SchedulerEventRecorder.html#attr_strings
// https://github.com/liferay/alloy-ui/blob/3.0.3-deprecated.65/src/aui-scheduler/js/aui-scheduler-view-week.js#L19
eventRecorder: new Y.SchedulerEventRecorder({
strings: {
'delete': 'borrar',
'description-hint': 'descripción insinuación',
cancel: 'cancelar',
description: 'descripción',
edit: 'editar',
save: 'salvar',
when: 'cuando'
}
})
});
});
* I don't recommend using Google Translate to internationalize a production application since there are many nuances to internationalization that a machine translation will miss.