|
That do/while loop doesn't look like it does anything except set some embedded data to the same value 10 times. If you want the difference between two Dates in days I'd use something like:code:
|
# ? Nov 18, 2015 20:23 |
|
|
# ? May 16, 2024 10:23 |
|
necrotic posted:That do/while loop doesn't look like it does anything except set some embedded data to the same value 10 times. If you want the difference between two Dates in days I'd use something like: Thanks for this. The code I have right now is working fine though most of the time, so is there something wrong with it that would cause it to behave inconsistently particularly on mobile devices? I don't want to change the code to something different unless I know it's going to fix my issue.
|
# ? Nov 18, 2015 20:29 |
|
Rosalind posted:First a few caveats: * Your indentation needs fixing. * Unnecessary extra semicolon at the very end of the code. * The line Math.round(difference) all by itself doesn't do anything. You need difference = Math.round(difference). * Try to avoid having two separate variables daydiff and difference, especially since they seem to do the same thing. * The test daydiff == NaN can be removed, this will always return false even when daydiff is NaN. * You can just do var newQuestionText = "on Day " + String(daydiff);. * Don't use .innerHTML, use .text. And everything said above.
|
# ? Nov 18, 2015 20:41 |
|
Rosalind posted:Thanks for this. The code I have right now is working fine though most of the time, so is there something wrong with it that would cause it to behave inconsistently particularly on mobile devices? I don't want to change the code to something different unless I know it's going to fix my issue. What is populating the field "day1date" which you use for surv1date? Is it a number of Unix milliseconds (a 13-digit number like "1447875934389"), or a string containing a date and time such as "December 17, 1995 03:24:00" or "1995-12-17T03:24:00"? If the latter, what time zone is that date in? Is it the client's local time zone, or is it always UTC? When JavaScript's Date constructor parses a single string containing the date and time, I believe it assumes that that date and time has been presented in UTC. But if the client's local time isn't UTC, then that means JavaScript will have constructed an incorrect date, leading to issues. Can you be more specific when you say it doesn't work? What error do you see? Does your code throw exceptions, does it return "NaN", does it return a value which is off by 1 day?
|
# ? Nov 18, 2015 20:52 |
|
qntm posted:When JavaScript's Date constructor parses a single string containing the date and time, I believe it assumes that that date and time has been presented in UTC. But if the client's local time isn't UTC, then that means JavaScript will have constructed an incorrect date, leading to issues. This sounds like the bug to me. Why even pass in a string to start with? Just get Date.now(), save that number in your <whatever>, and then compare to another Date.now() when the user completes the process. You are already dividing by a fixed number to get your days, why complicate it so much?
|
# ? Nov 18, 2015 20:56 |
|
qntm posted:What is populating the field "day1date" which you use for surv1date? Is it a number of Unix milliseconds (a 13-digit number like "1447875934389"), or a string containing a date and time such as "December 17, 1995 03:24:00" or "1995-12-17T03:24:00"? If the latter, what time zone is that date in? Is it the client's local time zone, or is it always UTC? day1day is a string that looks like "Friday, October 30, 2015". There's no time zone since we set all the times = 0 in the javascript, but we're located in EST as are all the people taking the survey. Unfortunately I've been unable to replicate the problem myself. I get emails when our participants encounter a survey error and what caused it. All I know is that daydiff is not calculating correctly for these people in that it checks to ensure that daydiff is a number. If it were off by a day, it should still work correctly.
|
# ? Nov 18, 2015 21:04 |
|
Rosalind posted:day1day is a string that looks like "Friday, October 30, 2015". There's no time zone since we set all the times = 0 in the javascript, but we're located in EST as are all the people taking the survey. Setting the hours/minutes/seconds/milliseconds doesn't eliminate the time zone, it just sets the time to 12AM in whatever timezone the host is in.
|
# ? Nov 18, 2015 21:08 |
|
Skandranon posted:Setting the hours/minutes/seconds/milliseconds doesn't eliminate the time zone, it just sets the time to 12AM in whatever timezone the host is in. Oh see this is stuff I never deal with as 90% of my work is statistical in nature and stuff like time zones are incredibly annoying to deal with. I am going to try the simplified code recommended by necrotic along with the suggestions from qntm and see if that improves things. I can also just calculate the daydiff later when we download the data for cleaning I suppose, but I liked calculating it in real time so we could tell the participants they were on day X of Y of their daily surveys.
|
# ? Nov 18, 2015 21:11 |
|
Oh hell, it's worse than I thought. I set my time zone to UTC+11 (Australia somewhere). If I get JS to parse a simple date (no time information)code:
code:
Unit tests would also help.
|
# ? Nov 18, 2015 21:18 |
|
Ok so the issue seems to be that the code isn't causing an error or that the day difference is being calculated as null or something weird, their devices aren't running the javascript at all. We dug into our backend data and if the value had been calculated, even incorrectly or as NaN, we'd be able to see it. There's just no value at all for any of these people. I'm going to contact Qualtrics support.
|
# ? Nov 18, 2015 21:34 |
|
Date's string constructor's parsing isn't even specified to handle the result of Date.prototype.toString, let alone anything else. Never use it.
|
# ? Nov 18, 2015 21:42 |
|
Yeah, date parsing is strictly the domain of purpose built libraries like 'moment'. Never never never try to do even moderate amounts of date and time stuff in JavaScript without a library. You will gently caress it up, guaranteed.
|
# ? Nov 18, 2015 22:47 |
|
Not to mention the ECMAScript standard up to ES6 specifically instructs browser developers to handle dates incorrectly.quote:The implementation of ECMAScript should not try to determine whether the exact time was subject to daylight saving time, but just whether daylight saving time would have been in effect if the current daylight saving time algorithm had been used at the time. This avoids complications such as taking into account the years that the locale observed daylight saving time year round.
|
# ? Nov 18, 2015 23:04 |
|
God made UTC, the rest is the work of man.
|
# ? Nov 18, 2015 23:09 |
|
qntm posted:God made UTC, the rest is the work of man.
|
# ? Nov 18, 2015 23:30 |
|
Vulture Culture posted:Did you know that to synchronize clocks between earth-based receivers and GPS satellites, the code needs to account for relativistic time dilation outside of Earth's gravity? And the dilation due to velocity (though not as much).
|
# ? Nov 19, 2015 13:17 |
|
qntm posted:God made UTC, the rest is the work of man. If God wanted us to have time zones, he would have something something something.... *goes back to bed*
|
# ? Nov 20, 2015 19:22 |
|
I'm sure this is a question with a really simple answer I'm just not getting. I'm trying to create a to-do list using angular, where each item has a checkbox that can be used to mark it as done. I'm using angular to generate the tasks from a list using ng-repeat, and the template for the checkbox is <input type="checkbox" class="check">. I've been trying to implement a button that marks all the tasks as done, but haven't had any luck. I've been trying different variations of code:
|
# ? Nov 22, 2015 15:50 |
|
Kuule hain nussivan posted:I'm sure this is a question with a really simple answer I'm just not getting. I'm trying to create a to-do list using angular, where each item has a checkbox that can be used to mark it as done. You are thinking of this backwards. You don't need to do things like "getElementsByClassName". The whole point of Angular is to get away from that. You should have a backing collection of items, that is your list that you are ng-repeating over. Your markAll function should simply go over that list and set the "checked" (or whatever) boolean to true. code:
Skandranon fucked around with this message at 17:56 on Nov 22, 2015 |
# ? Nov 22, 2015 17:54 |
|
Skandranon posted:You are thinking of this backwards. You don't need to do things like "getElementsByClassName". The whole point of Angular is to get away from that. You should have a backing collection of items, that is your list that you are ng-repeating over. Your markAll function should simply go over that list and set the "checked" (or whatever) boolean to true.
|
# ? Nov 22, 2015 17:57 |
|
Kuule hain nussivan posted:That was actually my original plan. I gave the tasks a done variable and had markAll work with that. I just couldn't figure out how to bind the checkbox elements to the boolean variable within the task object. code:
|
# ? Nov 22, 2015 18:01 |
|
Skandranon posted:
Nope, still can't get it to work
|
# ? Nov 22, 2015 18:22 |
|
Kuule hain nussivan posted:Nope, still can't get it to work IE or Chrome? If .checked = true doesn't work in Chrome, then you might be running into this: http://stackoverflow.com/questions/16950751/checked-checked-not-working-in-chrome.
|
# ? Nov 22, 2015 18:32 |
|
Kuule hain nussivan posted:Nope, still can't get it to work Can you be more specific about what isn't working? Beyond posting the basic "using checkboxes with Angular" code, it becomes really hard to speculate further on what could possibly be going wrong with your code without more information.
|
# ? Nov 22, 2015 19:04 |
|
Skandranon posted:Can you be more specific about what isn't working? Beyond posting the basic "using checkboxes with Angular" code, it becomes really hard to speculate further on what could possibly be going wrong with your code without more information.
|
# ? Nov 22, 2015 19:29 |
|
Kuule hain nussivan posted:I actually got it to work. The problem seemed to be that the for each loop I had set up to go through $scope.tasks wasn't working properly. Each task variable just wound up being just the number of the current index, rather than the object at said index, so the object values never got changed. Changed it to a for (i; i < x; i++) loop, and everything works fine. Coming from Java, I really dislike how a var can be goddamn anything in Javascript. Aargh, yeah, I should have seen it... I miss that a lot because I primarily use TypeScript, which supports the ES6 for...of, which DOES work as you and I thought for...in would. In short, you should convert to using TypeScript.
|
# ? Nov 22, 2015 19:32 |
|
Here's my lovely npm package, how can I improve it? Any glaring errors or bad implementations of ... anything? It's quite simple, but I'm hoping that I can use the feedback as a learning opportunity on what NOT to do, etc.
|
# ? Nov 25, 2015 09:37 |
|
Odette posted:Here's my lovely npm package, how can I improve it? Any glaring errors or bad implementations of ... anything? The function names getStory() and getInfo() are not technically accurate but at least they are short. MrMoo fucked around with this message at 16:27 on Nov 25, 2015 |
# ? Nov 25, 2015 16:22 |
|
Sigh, more problems which I have no idea how to fix. I have an Angular app which uses a Firebase service. The folder structure is /app.js /contollers/controller.js /services/firebase_service.js And in the HTML these are loaded in the order app, service, controller. I'm trying to inject the firebase service into the controller, but it keeps giving me an "Unknown provider: $firebaseArrayProvider <- $firebaseArray <- FirebaseService" error. My code is.. code:
|
# ? Nov 26, 2015 09:52 |
|
The error looks like it's trying to find $firebaseArray to inject into your FirebaseService and not finding it. What's $firebaseArray?
|
# ? Nov 26, 2015 10:19 |
|
Tao Jones posted:The error looks like it's trying to find $firebaseArray to inject into your FirebaseService and not finding it. What's $firebaseArray?
|
# ? Nov 26, 2015 14:28 |
|
Kuule hain nussivan posted:It's one of the services offered by Firebase. It works fine if I don't try to inject it into the controller, so I don't think it's an issue with FirebaseService not finding it. Firebase being some sort of Angular Module, which you've specified to load in your module with the name 'firebase'? When do you load firebase.js?
|
# ? Nov 26, 2015 17:52 |
|
Skandranon posted:Firebase being some sort of Angular Module, which you've specified to load in your module with the name 'firebase'? When do you load firebase.js?
|
# ? Nov 26, 2015 18:11 |
|
Kuule hain nussivan posted:That's loaded in the HTML, right after the main angular app. There is your problem, it has to load before it. Should be treated like a library, that your app depends upon.
|
# ? Nov 26, 2015 18:17 |
|
Skandranon posted:There is your problem, it has to load before it. Should be treated like a library, that your app depends upon. Edit: Apparently it was a version problem. Updating everything helped. Still only getting empty data, but at least it's not an error. Kuule hain nussivan fucked around with this message at 19:31 on Nov 26, 2015 |
# ? Nov 26, 2015 18:33 |
|
Kuule hain nussivan posted:No go. If I change the load order to firebase -> angularfire -> angular, I get a complaint that angular is missing, but firebase -> angular -> angularfire gives the same error. Ok, when you said "Angular app" you meant angular.js. That has to load before other modules, as all the other Angular modules need to call angular.module("",[]) just like you do. Something you are not doing that you should is specifying your DI as strings, as you mentioned earlier. Do this always, it's the proper way, examples that don't do this just haven't been updated.. This will allow minification to take place properly. Secondly, now that you aren't getting an injection error, you probably either aren't using Firebase correctly in some way. The Firebase API example has a step that either you are missing or simply ommited in your post code:
|
# ? Nov 26, 2015 21:49 |
|
I've never been good at Web development. I don't understand it at all. I went to live in the world of low level C instead. For shits and giggles I went with a group of friends to a Hackathon and we've walked away with something that both might win and we think might be a good startup idea to pursue over the summer break. I really need to get good at javascript to be much help. I stress the part of really good, because some of the libraries we have used are cryptic as gently caress. We are using Riot.js, Ventus.js and heaps of other things in some mashup. I want to be able to detangle this mess before it becomes a headache. So do you guys have any resources to help bring people up to speed on all this?
|
# ? Nov 30, 2015 10:31 |
|
Lord Windy posted:I've never been good at Web development. I don't understand it at all. I went to live in the world of low level C instead. For shits and giggles I went with a group of friends to a Hackathon and we've walked away with something that both might win and we think might be a good startup idea to pursue over the summer break. As a general rule, the "let's pull random javascript libraries that do cool things and smash them together" style of JS development is just a pain to work with. I would say: a) Minimize the library use in your project. If you don't really need the whole library, or can do it yourself, just cut it. Vanilla JS is almost always easier to deal with than library slop. b) Consider converting to a compile-to-JS language like typescript. Raw JS is more difficult to maintain than compile to JS languages. c) Minimize the amount of stuff done in the browser - web apis are easier to test and maintain, and it'll be easier to refactor when someone decides to get rid of your flavor of the month UI library.
|
# ? Nov 30, 2015 14:32 |
|
For me the first step to "getting" Javascript, was when I realized that Javascript has function scope. Any var you declare is visible everywhere in the function. Or at least it helped me not make as many mistakes. The second step probably was realizing that it has first class functions. And what first class functions are My hints are: Use strict mode and JSHint right from the start.
|
# ? Nov 30, 2015 14:49 |
|
|
# ? May 16, 2024 10:23 |
|
Wheany posted:My hints are:
|
# ? Nov 30, 2015 15:45 |