I'm trying to create a v-calendar with vuetify.
The problem is that I can't start at 10:00 and show 3:00 the next day.
How can I display it until 3 o'clock the next day?
<v-calendar
ref="calendar"
v-model="focus"
color="primary"
type="category"
category-show-all
:categories="categories"
:events="events"
:event-color="getEventColor"
first-interval=10
interval-minutes= 60
#change="fetchEvents()"
></v-calendar>
There is a solution but it's a bit hacky (doesn't seem natively supported by Vuetify). First, you'll need to use the prop interval-count
The number of intervals to display in the day view.
When you use this to show hours past midnight, the calendar will grow vertically to accommodate the additional hours, but will still not show the interval labels for those hours.
If we use another prop called show-interval-label, it takes a function that:
Checks if a given day and time should be displayed in the interval gutter of the day view.
Using the props together:
first-interval="10"
interval-minutes="60"
interval-count="18"
:show-interval-label="showInterval"
Here I define a method showInterval and in showInterval if I console.log all the intervals it receives, the first interval that is not displayed (1:00am) looks like this:
{
"date": "2022-11-14",
"time": "25:00",
"year": 2022,
"month": 11,
"day": 14,
"weekday": 1,
"hour": 26,
"minute": 0,
"hasDay": true,
"hasTime": true,
"past": false,
"present": false,
"future": true
}
Even if we return true for all intervals, the intervals after midnight still won't be displayed on the calendar. That is because the v-calendar template code knows after midnight it should only display intervals for the next day, but the interval object itself still has properties defining it using the previous day (date, day, weekday, etc)
To get these intervals to display we have to modify the object to look like this instead:
{
"date": "2022-11-15",
"time": "1:00",
"year": 2022,
"month": 11,
"day": 15,
"weekday": 2,
"hour": 1,
"minute": 0,
"hasDay": true,
"hasTime": true,
"past": false,
"present": false,
"future": true
}
The full code for doing so is below which I also included in a codepen
showInterval(dateObj) {
console.log('dateObj', dateObj);
if (dateObj.hour > 24) {
const extraDays = Math.floor(dateObj.hour / 24);
const newHour = dateObj.hour === 24 ? 24 : dateObj.hour % 24;
const newDay = dateObj.weekday + extraDays === 7 ? 7 : (dateObj.weekday + extraDays) % 7;
dateObj.hour = newHour;
dateObj.weekday = newDay;
dateObj.day = dateObj.day + extraDays;
dateObj.date = this.addDays(dateObj.date, extraDays);
dateObj.time = this.subtractTime(dateObj.time, extraDays);
}
return true;
},
addDays(date, days) {
var result = new Date(date);
result.setDate(result.getDate() + days);
return result.toISOString().slice(0, 10);
},
subtractTime(time, days) {
const timeArr = time.split(':');
const newHour = Number(timeArr[0]) - 24 * days;
return newHour + ':' + timeArr.slice(1).join();
}
Related
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');
I have a JSON object stored in Azure Cosmos DB, and I'm seeing if there's a way to write workable queries doing basic things like Order By.
The structure looks something like :
[
{
"id":"id1",
"title":"test title",
"dataRecord":{
"version":1,
"dataRecordItems":[
{
"itemTitle":"item title 1",
"type":"string",
"value":"My First Title"
},
{
"itemTitle":"item number",
"type":"number",
"value":1
},
{
"itemTitle":"date",
"type":"date",
"value":"21/11/2019 00:00:00"
}
]
}
},
{
"id":"id2",
"title":"test title again",
"dataRecord":{
"version":1,
"dataRecordItems":[
{
"itemTitle":"item title 2",
"type":"string",
"value":"My Second Title"
},
{
"itemTitle":"item number",
"type":"number",
"value":2
},
{
"itemTitle":"date",
"type":"date",
"value":"20/11/2019 00:00:00"
}
]
}
]
I can use ARRAY_CONTAINS to find objects with a particular value, but I run into all kinds of issues if I try to sort by an the value of an object which has the title of "date".
So, as an example, I'd like to be able to say something like (pseudoish code here):
SELECT * FROM c WHERE
ARRAY_CONTAINS(c.dataRecord.dataRecordItems,
{"itemTitle":"item title 2", "value" : "My Second Title"}, true)
AND
ARRAY_CONTAINS(c.dataRecord.dataRecordItems,{"itemTitle":"item number", "value" : 2}, true)
ORDER BY < *** SOMEHOW GET THE DATE HERE from itemTitle = date ***
Then, in this simple case, I would everything returned, but ordered by date.
Obviously in the future I would be pulling out individual fields, but it's all kind of moot if I can't do the first part.
Just wondering if anyone has any great ideas.
Cheers!
You need to store the date in ISO 8601 format:
Year:
YYYY (eg 1997)
Year and month:
YYYY-MM (eg 1997-07)
Complete date:
YYYY-MM-DD (eg 1997-07-16)
Complete date plus hours and minutes:
YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
Complete date plus hours, minutes and seconds:
YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
Complete date plus hours, minutes, seconds and a decimal fraction of a
second
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
where:
YYYY = four-digit year
MM = two-digit month (01=January, etc.)
DD = two-digit day of month (01 through 31)
hh = two digits of hour (00 through 23) (am/pm NOT allowed)
mm = two digits of minute (00 through 59)
ss = two digits of second (00 through 59)
s = one or more digits representing a decimal fraction of a second
TZD = time zone designator (Z or +hh:mm or -hh:mm)
https://www.w3.org/TR/NOTE-datetime
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 :)