Results 1 to 9 of 9

  1. Post
    #1

    Holy shit, today I wanted to reformat a date in Javascript - whingepost

    This is just a whinge post, it doesn't need a fix.

    But has anyone actually tried it?

    So I had a nice standard ISO date and wanted to convert it to "dd MMM yyyy" without installing a class.

    I've been Googling all over the place and literally everything points to, "parse the date three times using get month, get year and get day, then create an array that holds all of the month by name, and call it relative to the month number".

    Heaven ****ing forbid you want to output the users locale in that format.

    Literally every other programming language has a format function where you just chuck, say, "dd MMM yyyy" into the function and your input date and it spits out something nice and usable.

    Which I'm going to use, I'm going to dump a format in my query and load my SQL server up even more so I can get a nice, proper output without ****ing around with the nonsense that is Javascript.

    EDIT: mySQL =
    Code:
    DATE_FORMAT(PA.endDate, "%e %b %Y") AS endDate,
    And done.

  2. Post
    #2
    That's what you get for using javascript TBH

  3. Post
    #3
    Abo wrote:
    That's what you get for using javascript TBH
    Lol would you suggest a web Java app for a dynamic front end? ActiveX controls?

  4. Post
    #4
    suntoucher wrote:
    Lol would you suggest a web Java app for a dynamic front end? ActiveX controls?
    yea, you don't really have any choice but to use javashit these days for web


    doesn't mean it's not a steaming pile of shit language though

  5. Post
    #5
    At a cursory glance, it seems like the only way to do it in JS without it being a pain in the ass is with moment.js using moment.locale();

    Otherwise maybe look into Typescript?

    I mean, this is something I'd just handle serverside in PHP any case, unless there's a specific requirement against it.
    Last edited by BURN_BABY; 12th January 2020 at 2:21 pm.

  6. Post
    #6
    BURN_BABY wrote:
    At a cursory glance, it seems like the only way to do it in JS without it being a pain in the ass is with moment.js using moment.locale();

    Otherwise maybe look into Typescript?

    I mean, this is something I'd just handle serverside in PHP any case, unless there's a specific requirement against it.
    I don't want to add more third party classes, trying to keep it as trim as possible, and TypeScript just compiles to JS so I'd rather know how to do it on the low level then get stuck later learning TypeScript and find it's not capable of something that JavaScript can do. Then have to know JS anyway, also makes it easier to maintain using as few languages as possible.

    Doing it in JS because it's building a preview box of an item with a date on the fly using data from an array. Just dumping the query results using JSON encode so I don't have to manually build an array from another array, so to pull it from PHP means I'd have to store the data somewhere on the page or manually rebuild the array from the SQL output into the JS array.

    So I have a JS array of products (mySQL > PHP JSON encode), I click one, instead of going to a new page it gives me product data as an overlay with not yet seen data on the page which shows said date.

  7. Post
    #7
    Your design is flawed my friend.

    With what you've done the user is going to have to sit there and wait for the entire product catalog to come back from the source including all its information. Might be fine when you've got a handful of items, but what's going to happen when that payload grows?

    But yes, please just use something like moment.js. Nothing worse than seeing someones code who hasn't used industry standard libraries because "I want it as light as possible but I still pull in the entire product catalog in a single request"

  8. Post
    #8
    Tend to agree with Privoxy here, even though it pains me

    The client side is the correct place to do the work in this case - especially with timezones and locality.

    Remember that you can leverage browser caching for client side resources - which means page load is only affected once for the load, and then it's just the parsing and execution - very minimal overhead.

    We are currently looking at replacing momentjs @ work - because it's a fairly large chunk of js, and replacing it with dayjs.

    https://github.com/iamkun/dayjs

  9. Post
    #9
    Privoxy wrote:
    Your design is flawed my friend.

    With what you've done the user is going to have to sit there and wait for the entire product catalog to come back from the source including all its information. Might be fine when you've got a handful of items, but what's going to happen when that payload grows?

    But yes, please just use something like moment.js. Nothing worse than seeing someones code who hasn't used industry standard libraries because "I want it as light as possible but I still pull in the entire product catalog in a single request"
    Nah that's sorted, it only grabs the page results, not the entire product catalog and it's just text, the records are already being hit for filtering so it may as well grab more data.