Loading Events in Ionic2_Calendar - angularjs

I implemented a version of the ionic2-Calender. It works very fine. When i have no events in my eventSource and create an Event, the event is displayed correctly.
The Problem comes when I am trying to load Events from my Storage. I am always getting this error:
TypeError: eventStartTime.getFullYear is not a function at
MonthViewComponent.onDataLoaded (ionic2-calendar.js:1768) at
MonthViewComponent.ngOnChanges (ionic2-calendar.js:1614) at
MonthViewComponent.wrapOnChangesHook_inPreviousChangesStorage
Can anyone help me ?

Based on the issue here, it says the startTime property of the event should be a date object.
This indicates that the event startTime probably is not a valid Date
object. Could you double check what's the type of startTime? If it's a
string, you need to convert it into Date object.
I have also stumbled upon this when using web storage to load the calendar, which gets converted to string data type.
The solution is very simple as we only need to iterate through the value from the storage and convert it to date before setting the value of the model itself.
var eventsFromStorage = window.localStorage.get("eventsCalendar");
var countData = eventsFromStorage.length;
for (i = 0; i < countData; i++) {
eventsFromStorage[i].startTime = new Date(eventsFromStorage[i].startTime);
eventsFromStorage[i].endTime = new Date(eventsFromStorage[i].endTime);
}
this.eventsModel = eventsFromStorage;

Related

How to change "val" values in an object without changing the definition to "var"?

I have a complex Kotlin data class, say something like this:
data class Post(
val message: Message,
val dateAndTime: LocalTime,
val postAuthor: Author?,
val visitorsVisitedTimes: List<Pair<LocalTime, Author>>
)
and each of Message, LocalTime, ... are different data classes.
I have an object of above Post data class. I want to parse it, access visitorsVisitedTimes field value, for each pair, replace Author object with corresponding postAuthor. I have to make similar changes in the Message object as well.
And I don't want to make changes in the class definition.
One way would be to convert this object into a json string, parse it, make require changes and cast it back to Post::class.java and return it.
I did something like this:
// input is an object of Post::class
var jsonString: String = Gson().toJson(input)
// parse the json string, make required changes
var objectFromJson: Post = Gson().fromJson(jsonString, Post::class.java)
return objectFromJson
But, I'm not sure how to make required changes in the Json string.
How can I do that, if not, is there any other way to do the task?
Create a copy of an object, see https://kotlinlang.org/docs/data-classes.html.
val newPost = post.copy(
message = post.message.copy(text = "some text"),
postAuthor = Author(...)
)

How to get raw date string from date picker?

I'm struggling for hours with this seemingly trivial issue.
I have a antd datepicker on my page.
Whenever I choose a date, instead of giving me the date I chose, it gives me a messy moment object, which I can't figure out how to read.
All I want is that when I choose "2020-01-18", it should give me precisely this string that the user chose, regardless of timezone, preferably in ISO format.
This is not a multi-national website. I just need a plain vanilla date so I can send it to the server, store in db, whatever.
Here are some of my trials, so far no luck:
var fltval = e;
if (isMoment(fltval)) {
var dat = fltval.toDate();
//dat.setUTCHours(0)
fltval = dat.toISOString(); // fltval.toISOString(false)
var a = dat.toUTCString();
//var b = dat.toLocaleString()
}
It keeps on moving with a few hours, probably to compensate for some timezone bias
UPDATE 1:
the datestring is data-wise correct. But its not ISO, so I cant use it correctly. I might try to parse this, but I cannot find a way to parse a string to date with a specific format.
UPDATE 2:
I also tried adding the bias manually, but for some reason the bias is 0
var dat = pickerval.toDate()
var bias = Date.prototype.getTimezoneOffset()// this is 0...
var bias2 = dat.getTimezoneOffset()// and this too is 0
var d2 = new Date(dat.getTime()+bias)
var mystring= dat.toISOString() //still wrong
Thanks!
Javascript date functions can be used,
I assume you are getting in 2022-01-03T11:19:07.946Z format then
date.toISOString().slice(0, 10)
to 2022-01-03
There are 2 ways to get the date string:
Use the moment.format api:
date.format("yyyy-MM-DD")
Use the date string that is passed to the onChange as second parameter
Here is a Link.
I am assuming your code snippet is inside the onChange method. This gives you a moment and a date string to work with (the first and second parameters of the function respectively).
You have a few options. You could set the format prop on the DatePicker to match the format of the string you want. Then just use the date string. Or you can use the moment object as Domino987 described.

How to create array of coordinates?

I am working on geo location search in nodejs backend. And mongodb is the database. In order to do that, I am getting values from front end. I am using map getbound to get viewport data. Below are some variables that holds latitude and longitude.
var topLeftLong = parseFloat(req.body.topLeftLong);
var topLeftLat = parseFloat(req.body.topLeftLat);
var topRightLong = parseFloat(req.body.topRightLong);
var topRightLat = parseFloat(req.body.topRightLat);
var bottomRightLong = parseFloat(req.body.bottomRightLong);
var bottomRightLat = parseFloat(req.body.bottomRightLat);
var bottomLeftLong = parseFloat(req.body.bottomLeftLong);
var bottomLeftLat = parseFloat(req.body.bottomLeftLat);
Though I am getting these data, I want to put latitude and longitude in an array. But whenever I tried to push data in the array, I get the below error.
Seems like wrong data type is to blame. In your code if you applied cast, for e.g. (int)string-var, then it could be the error due to that. Data types are important. Mismatch data types would cause errors.

Intern test returns incorrect value for range input

I have a test that checks the value an HTML5 range input.
return this.remote
// etc.
.findById('range')
.getAttribute("value")
.then(function(val){
expect(parseInt(val)).to.equal(2);
});
The value is correct when I check its initial value, but if I change the value then check, it has not been updated. I found that the value doesn't update in the developer tools either. I tried using
.sleep(3000)
between changing the value and calling
.getAttribute('value')
but that didnt' seem to be the issue.
In this JSfiddle, inspecting the range element with your browser's developer tools will show the title change, but the value does not (even though the value is correctly changed in the textbox). So this may be an issue with the webdriver, but I'd like to know if anyone has run into this issue.
Is this related to the test's failure to get the updated value? Is there another method I can use to read values(attributes)?
Edit:
It seems like the browser's onchange/oninput event is not triggering properly (similar problems: WebDriver: Change event not firing and Why does the jquery change event not trigger when I set the value of a select using val()?), and the webdriver is possibly not able to, either. Do I have to add Jquery as a define for my test, even though I only need to use trigger() ? Or is there another solution?
Edit2: I've added a better example of how I'm using the range input in this new JSfiddle. I added plus/minus buttons, which fail to trigger the change event that should update the value attribute of the range input, (and which fails to enter the value into the textbox).
You could fire the change event manually in your test. I was able to get the 'textValue' input in your JSFiddle to update that way and I imagine it might work similarly in your test.
rangeBar = document.querySelector('#range');
function myFire(element, eventType) {
var myEvent = document.createEvent('UIEvent');
myEvent.initEvent(
eventType, // event type
true, // can bubble?
true // cancelable?
);
element.dispatchEvent(myEvent);
}
myFire(rangeBar, 'change');
This comes up often enough that I have a helper in my base test class (Java)
public enum SeleniumEvent
{blur,change,mousedown,mouseup,click,reset,select,submit,abort,error,load,mouseout,mouseover,unload,keyup,focus}
public void fireEvent(WebElement el, SeleniumEvent event)
{
((JavascriptExecutor) getDriver()).executeScript(""+
"var element = arguments[0];" +
"var eventType = arguments[1];" +
"var myEvent = document.createEvent('UIEvent');\n" +
"myEvent.initEvent(\n" +
" eventType, // event type\n" +
" true, // can bubble?\n" +
" true // cancelable?\n" +
");\n" +
"element.dispatchEvent(myEvent);", el, event.toString());
}
Another thought. getAttribute("value") might not be getting what you think it does. In JavaScript, document.querySelector('#range').getAttribute('value') always returns the hard-coded value attribute (i.e. the default or initial value), not the input's current value.
document.querySelector('#range').value returns the current value.

Angular UI datepicker giving me a UTC converted string. How to parse it back to local time accounting for the time difference?

I am currently running into issues with datepicker automatically converting my time to UTC. Is there anything I can pass into datepicker for it to not give me back a UTC converted string? For example the user picks March 19 on the calendar and the returned string would be something like this
'2014-03-19T04:00:00.000Z'
What I want is ->
'2014-03-19T00:00:00-04:00'
What I am trying now (sort of hacking around it) is trying to use moment js to convert it back to my desired (expected) format, but I am having trouble doing so without hardcoding a subtraction in there. I want to be able to convert it from UTC back to local time.
Does anyone know of a solution to this using moment js or angular?
I ran into the same problem and used a filter that adjusts the date and time using the local data to get around it:
filter('adjustDatepicker', ['$filter', function($filter){
var dateFilter = $filter('date');
return function(dateToFix){
var localDate, localTime, localOffset, adjustedDate;
localDate = new Date(dateToFix);
localTime = localDate.getTime();
localOffset = localDate.getTimezoneOffset() * 60000;
adjustedDate = new Date(localTime + localOffset);
return dateFilter(adjustedDate, 'MM/dd/yyyy');
};
}])
Use it like this in your template file:
{{details.datetomodify | adjustDatepicker}}
I think new Date('2014-03-19T04:00:00.000Z').toString() will give you the local version of the UTC time.

Resources