« first day (3322 days earlier)      last day (1609 days later) » 

12:06 AM
Not exactly JS but HTML. Does someone knows how to force the child of a flex container to take all remaining space instead of the necessary?
 
flex-grow: 1?
 
@KostasX Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
That would work for one child, but I have three of them and I would like to each one take a bit of that space
 
You can apply the flex-grow: 1 to all of them
 
12:32 AM
Greetings Guys. Please I am building a website that uses an external api. The api page is available to me when am logged in into the site but doesn't open when am signed out. Please is there a way of bypassing this using stream ? please any suggestion, contribution and help will be highly appreciated. AM STOCKED. Thanks
 
 
1 hour later…
1:54 AM
@NobMusic Proabably not. Authentication wouldn't be very useful if you could just ignore it.
We can't really help based on the extremely vague description you've given.
 
@NobMusic Thats odd. Not sure why an API would require auth. Usually API keys are used. In any event, your best bet would be to proxy api requests through your site. (User requests your site which injects the credentials into the request and forwards it to the API). Be cautious of the security implications of doing that. As meager said, most description would be helpful.
 
2:54 AM
This is a very interesting video if anyone is interested. Talks about chrome dev tools are reverse engineering:
 
 
2 hours later…
4:41 AM
I have a class with a counter property inside it (class MyClass { let count = 0; }). I create an instance of this class and then pass the variable to different functions, each of which do something similar to classInstance.count += 1. This works fine, value increases as expected. Now I have a different file which has a similar set of functions and I export those functions so I can use them in the main file. Issue is, when those functions modify the instance, it doesn't change the property.
Can I not have functions from a different file modify this instance's properties?
 
Folks, what javascript api gives an indication of the amount of data downloaded by a webpage when we visit it? Or it is something the browsers calculate (i.e. take a cumulative sum) just by looking at response headers (content-length)?
 
 
2 hours later…
6:53 AM
CSRF prevention using a token works because adding a unique token to the form submission would require a potential attacker to gain access to that token to make a valid request?
 
7:35 AM
Hi guys
 
@Developer00 Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
I have some problems with Dates
 
You got a sloth as profile picture, I will try my best to help you!
 
I'm using getHours() but it returns the actual hour+1
@geisterfurz007 Thanks :D
And on Mac +2
The countdown should stop today at 17.30
 
Are both devices in the same timezone?
 
7:38 AM
On my windows pc (8.35 local time) it signs 9:55:00
on my mac (8.35 still) it signs 10:55
I tried using getUTCHours()
It still showed +1 hour on mac
 
That is... weird to say the least!
Did you run the command in the console of the browsers you used?
Just to make sure it's actually because of that or there is some other fault?
 
the timerzones are correct (CET)
 
So my question is getting down voted because it is a real problem that is not easy to answer. Sigh...
 
@geisterfurz007 I'm checking rn
so
I'm getting the expiration date from a json file
I'm using this site epochconverter.com to check if the timestamp is correct
 
Could you outline a little what you are doing in general? I am starting to get a little confused :D
 
7:45 AM
I'm doing a landing page for the black friday
It features a countdown since every day there are new promotions
the page's data are retrieved in a json file, including the expiration date of the countdown
Written like this: "2019-11-20T17:30:00"
The code simply gets this data and converts it using Date.parse()
then subtracts the current date and the expiration date
parse the result
and shows it
 
Ok, that helped! First two things I would check are
1) does new Date(Date.now()).getHours() return the same thing in both browsers
2) do both browsers parse the text form of the date the same
 
do you have reason to believe the timestamp would be incorrect?
 
@Neil you're everywhere mate
 
people don't normally write dates like "2019-11-20T17:30:00
 
@Developer00 It's horrible, isn't it?
 
7:50 AM
@Developer00 Well what god isn't everywhere? Not a very good one I dare say
 
@geisterfurz007 Date.now() is kept as timestamp
not converted into hours
@Neil :D
@Neil There's another way to parse date from string?
 
@Developer00 moment.js does this sort of thing
it's a fairly compact library and supports any format
 
I'll search
 
@Developer00 I know but maybe (for whatever reason) the mac creates a different date
You could also just do new Date(Date.now()); in both browsers to see if there is any difference
 
The date is the same
just 100 ms of latency
due to the page loading time
 
7:59 AM
And both browsers parse the date the same as well?
 
do you really care about 100ms of latency?
 
No, that was just as answer to my question, I guess :D
 
if the black friday deal ends 100ms sooner or later than the one you show, is that really a big deal?
 
The problem is that a mac and a windows machine show an hour difference @Neil
 
so add/remove an hour :P
 
8:02 AM
if (computer === 'mac') removeAdditionalHour();
Looks legit!
 
I assume the backend is always the same
and won't change from windows pc to mac at random times
so that's kind of unnecessary
 
And if you remove an hour on the backend to have it show correctly on mac, it's wrong on windows
 
which doesn't matter, because the backend is always mac
 
@geisterfurz007 they both give me Wed Nov 20 2019 09:03:03 GMT+0100 (CET)
 
@Neil the backend isn't the problem
 
8:04 AM
It would seem the backend is the problem though
The frontend would give the same value ..
 
@Developer00 When throwing 2019-11-20T17:30:00 into Date.parse?
@Neil Don't underestimate the power of mac :')
 
I've never been a big mac user. I don't really like Apple that much :)
they initially promoted that they were different from Microsoft and ultimately were the same if not worse
That's sort of off-topic, but anyway
 
They return 2 different timestamps
1 hour apart
So the Date.parse works differently on mac
and on windows
 
Can you change the presentation of the date in the json file you are requesting?
So that instead of "2019-11-20T17:30:00", you get the proper epoch for that time?
 
and if I use Date(expirationDate) it returns me the current date
 
8:10 AM
if one server says 17:30 and another says 16:30, the front end can't really do anything about that
 
it's like (Date(1574267400000)) = now
it should be 17.30
 
who is the front end to say that it isn't actually 17:30 or actually 16:30?
 
@Neil NEIL >.>
 
the backend is the authority here
you just have to determine which one is wrong, and fix it
 
The process is: Frontend requests timestamp from json -> frontend parses that timestamp -> frontend calculates the difference between current date and parsed timestamp
There is only one backend
And only one frontend.
 
8:11 AM
so where's the problem?
 
But the frontend behaves differently on the mac browser compared to the windows browser
 
probably has nothing to do with system
and all to do with time zone
or daylight saving
one or the other
 
Even thought the 2 pc are in the same timezone?
have the same clock settings
 
one pc can be in the same time zone but configured to be in another
 
I checked
 
8:13 AM
I can configure my pc to act as if it were in tokyo
 
they're both set to +1UTC
CET*
which is my timezone
 
is daylight saving time in effect for CET?
I think it is, isn't it?
 
by using getUTCHours I'm getting the windows work as it's supposed to be
at least
 
Try this on both browsers in the console: new Date().isDstObserved()
wait sorry, that doesn't exist
Date.prototype.isDstObserved = function () {
    return this.getTimezoneOffset() < this.stdTimezoneOffset();
}
 
Hi everyone,

I am trying to write a function with the help of Higher Order Functions that returns a trimmed string but only with complete words falling in the limit. Below is the code for it but is there a way to minimize the map function therein or use any other function instead?

return str
    .split(' ')
    .map(term => {
      if ((limit -= term.length) >= 0) {
        limit--;
        return term;
      } else {
        return '';
      }
    })
    .join(' ');

Thanks
 
8:19 AM
@m.sohail Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq. For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
@m.sohail Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
stdTimezoneOffset is not a function ._.
 
@m.sohail Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq. For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
 
Date.prototype.stdTimezoneOffset = function () {
    var jan = new Date(this.getFullYear(), 0, 1);
    var jul = new Date(this.getFullYear(), 6, 1);
    return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
}
 
@Neil it returns undefined
 
@Developer00 you have to also define stdTimezoneOffset, sorry
It's just to see if daylight saving is in effect in both cases
 
8:24 AM
Still undefined
nvm I missed the brackets
it doesn't do anything
 
what do you mean it doesn't do anything?
 
You should be able to run new Date().isDstObserved() in the browser console.
 
12 mins ago, by Neil
Try this on both browsers in the console: new Date().isDstObserved()
 
@Neil ...
 
@KarelG what?
 
8:29 AM
don't extend native prototypes
 
that answer got 290 upvotes, and we're using it to determine the type of problem he has, not as a permanent solution
 
Date(...).isDstObserved is not a function
 
143
Q: How to check if the DST (Daylight Saving Time) is in effect and if it is what's the offset?

Jo SmoThis is a bit of my JS code for which this is needed: var secDiff = Math.abs(Math.round((utc_date-this.premiere_date)/1000)); this.years = this.calculateUnit(secDiff,(86400*365)); this.days = this.calculateUnit(secDiff-(this.years*(86400*365)),86400); this.hours = this.calculateUnit((secDiff-(th...

 
Date.prototype.stdTimezoneOffset = function () {
    var jan = new Date(this.getFullYear(), 0, 1);
    var jul = new Date(this.getFullYear(), 6, 1);
    return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
}

Date.prototype.isDstObserved = function () {
    return this.getTimezoneOffset() < this.stdTimezoneOffset();
}

new Date().isDstObserved();
Paste that in the console. It should not show the error you got.
 
-.-
 
8:31 AM
@KarelG 😠
 
@KarelG there you go. Rewrite the solution written here to appease your Asperger tendencies :P
 
@Developer00 is it possible to expand that json response?
 
unexpected token: identifier
 
if so, just include "currentDate"
 
@Developer00 where is "identifier" written here?
 
8:32 AM
then you don't have to worry about browser's date interpretation
 
Impressive. It just says "false" for me.
@KarelG In that case you could just as well calculate the difference in the backend
 
it was firefox
lmao
it returns false
 
Ok and on the mac?
 
@Developer00 do both browsers do this? or just one?
 
@geisterfurz007 not if you want to tick the time. With the current date, you cna bring your local browser time in sync with what you got
but yes, normally seen the Date API is sufficient for this
I just revert to UTC
and use the diff when displaying it
 
8:36 AM
@KarelG yes, but you can't ask every user of your website to revert their timezone to UTC and refresh the page, can you?
nor can you convert yourself to UTC and subtract the difference if you don't understand why two browsers under the same time zone interpret the date in two separate ways
 
I didn'false = $2
i guess it's false
on both pc
 
59 mins ago, by Developer00
It still showed +1 hour on mac
@Developer00 Can you alter the JSON you are getting the expiration date from?
 
hmm
 
@geisterfurz007 yes
@KarelG it still shows +1 on mac
 
8:39 AM
@Developer00 Then stop using the format you are currently using and switch to the epoch timestamp.
 
Try this on both browsers: new Date().getUTCHours()
 
@Developer00 can you do (new Date()).toUTCString() on both browsers? and display it here?
I am curious at the last part of the ISO string
 
since it's an hour difference, I keep thinking it's a daylight saving time issue
assuming of course the time zone is the same as he claims
 
@geisterfurz007 so I have to write the date as timestamp every day?
 
What are you currently doing? Writing the date as timestamp every day but in a different format?
 
8:42 AM
@KarelG both 8:42
 
well ?
 
@geisterfurz007 writing the date and converting it to timestamp
 
@Developer00 show the full string please
 
"Wed, 20 Nov 2019 08:41:55 GMT"
"Wed, 20 Nov 2019 08:42:34 GMT" = $2
 
well seems correct
 
8:44 AM
@Developer00 So you can convert it to a different timestamp format, no?
 
doesn't it convert to unix timestamp as default?
 
if both utc strings are correct, how do you get differences?
 
I don't know!
 
@KarelG The problem is Date.parse
 
oh ... that
that is utterly unreliable
 
8:47 AM
The date.parse acts differently
 
42 mins ago, by geisterfurz007
@Developer00 When throwing 2019-11-20T17:30:00 into Date.parse?
 
never use that
parse the date at your own or use an existing library
(the parsing is easier to do if it is only for that page)
and use the new date(year, month, day, hour, minute, second) construct
 
oh
I'll try
 
@KarelG regex *-*
 
@geisterfurz007 es2018 introduces named capturing groups which is handy for this.
 
8:52 AM
Oh, that's neat!
 
It worked
lmao
 
1 hour ago, by Neil
@Developer00 moment.js does this sort of thing
 
2hours to get what was the problem
 
moral of the story: native javascript date support is shit
 
did not know that you were using the date construct with string
 
8:53 AM
I prefer using plain js or the js libs that are already on the server
@Neil yep
 
@Neil eh, aside from localization and the new Date(string) it is fine
 
thank you all
 
when is localization not a problem these days?
You're lucky nowadays to not have to worry about Japanese characters
 
Great, now that this is done, I can enable my userscript, that just closes the browsertab when opening chat.stackoverflow.com and makes my word icon in the taskbar blink to tell me to get the shit back to my thesis :D
 
University student?
 
9:05 AM
Hi everybody
 
@Baldráni \o
 
How your doin ?
 
@Neil I've seen worse
 
hi Baldrani
and Ben
 
@BenFortune storytime! :)
 
9:14 AM
PHP
nuff said
 
😏
 
strtotime is just magic with no actual logic
 
😛
that's a forgery
 
9:28 AM
@BenFortune It's just magic
 
9:48 AM
is there any specific way to show some element based on logged in user in angular? and I am not talking about the whole component.
 
10:29 AM
no there isn't any specific way. you need to give that custom based on your requirement.
 
^
 
 
2 hours later…
12:08 PM
hihi
 
hola
 
does it look weird the way the notifricatios open?
 
@BenBeri that is subjective
if that's a CSS animation, you can do it from top-down instead of center-out
 
You mean like make it open with scale but instead of center-out, make it right-top corner to bottom-left corner animation open?
The question how do you do it ?
 
12:25 PM
what do you use for the animation?
 
i simply do css keyframe
from scale 0 to scale 1
with tranisiton
 
Hey KarelG, I remember we had a debate about using the with interpreter at one point
I was reading up on it again, and it doesnt seem to have much of a negative impact at all, infact it improves performance: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
Only thing I noticed is that it ignores, or more in fact runs code slower if you place un-needed code-blocks inside the with statement (But why would you anyways)
And, including messing up the readability.... hmmm idk
 
@BenBeri change it to height, from 0 to desired height
cannot build a PoC right now, but I am certian it is possible that way. In meanwhile you can stick with the current one. it works, which is important
 
If I set height 0 to height 100% it kinda looks bad like the content inside of it animates very weirdly
i tried that
 
@TaylorS there is a big red box at the top. and it gets blocked in ES5+ strict mode (of which I sometimes use ...)
 
12:40 PM
Still dont get the "strict" and "loose"
dont know how to use the different types, and I dont know if its even important
 
it is true that the readability is based on personal opinion
yet, why use with if there are simpler "workarounds" for that
using with adds unnecessary scoping and ambiguity
 
True that you can make workarounds for repetitive code
 
see this in live, i did what u said
 
like getElementById
Like, in one of my projects, I have over 50 of them, so I made this
function gid(id) {
 var a = document.getElementById(id);
 return a;
}
 
12:47 PM
ops
 
But, for me, with is Useful for code that isnt Repetitive, but uses the same central variable
 
@TaylorS it can be more shorter and concise :P
 
Like I can simplify a large chunk of bulky crap to something like this: (Snippet of my load-game code from an old clicker game I made)
with (doc) {
  with (data) {
   CAS.innerHTML = "Cash: $" + CA;
   DS.innerHTML = "Lvl " + DL + " Diamonds: " + D;
   RS.innerHTML = "Lvl " + RL + " Rubies: " + R;
   GS.innerHTML = "Lvl " + GL + " Gold: " + G;
   IS.innerHTML = "Lvl " + IL + " Iron: " + I;
   CS.innerHTML = "Lvl " + CL + " Coal: " + C;
  }
 }
Well, I could simplify that even more
like way more
so yes, with can be replaced by "functional variables" as I call them... by sticking variables that use function arguments and window[] to make very short code
but making a function thats called EVERY TIME a value changes... thats just plain unefficient
 
Hey this solved this for me :)
@keyframes open-notifications {
  from {
    transform: scale(0);
    transform-origin: top right;
  }
  to {
    transform: scale(1);
    transform-origin: top right;
  }
}
 
oh... I forgot transform scale was a thing
 
12:56 PM
Now it opens nicely from top-right
 

« first day (3322 days earlier)      last day (1609 days later) »