Description
Agustín Moyano
2020-01-17 18:12:44 UTC
Created attachment 97567 [details] [review] Bug 24455: Add moment library in opac This patch adds koha-tmpl/opac-tmpl/bootstrap/lib/moment.min.js in order to use the moment library (https://momentjs.com/) Created attachment 97568 [details] [review] Bug 24455: Add moment-timezone library in opac This patch adds koha-tmpl/opac-tmpl/bootstrap/lib/moment-timezone-with-data-10-year-range.min.js in order to use the moment library with timezones (https://momentjs.com/timezone/) Created attachment 97569 [details] [review] Bug 24455: Add JS functions to format date and datetime strings This patch adds the koha-tmpl/opac-tmpl/bootstrap/en/includes/js-date-format.inc file (date-format.inc whas not available as name) When you include that file in your TT, you'll get the following functions available: 1. $date(raw_date_string, options) This function parses a date string, as produced by an api call, and returns the corresponding date formatted according to 'dateformat' and 'TimeFormat' parameters. For example: // dateformat: us // timeformat: 12hr // Timezone: UTC $date('2020-03-23T15:00:00+01:00') // You will get '03/23/2020' $date('2020-03-23T15:00:00+01:00', {withtime: true}) // You will get '03/23/2020 14:00' $date('2020-03-23T15:00:00+01:00', {withtime: true, tz: 'Europe/Paris'}) // You will get '03/23/2020 15:00+01:00' Options: * dateformat: override date format as configured in staff interface (accepts also 'rfc3339') * timeformat: override time format as configured in staff client (available options are '12hr' and '24hr') * withtime: also print the time part (default false) * tz: set the timezone 2. $datetime(raw_date_string, option) The same as $date but sets withtime to true 3. $time(raw_date_string, option) The same as $datetime but shows only the time part To test you must implement and test bug 20936, where it will be used Created attachment 97574 [details] [review] Bug 24455: Add moment library in opac This patch adds koha-tmpl/opac-tmpl/bootstrap/lib/moment.min.js in order to use the moment library (https://momentjs.com/) Created attachment 97575 [details] [review] Bug 24455: Add moment library in staff This patch adds koha-tmpl/intranet-tmpl/lib/moment/moment.min.js in order to use the moment library (https://momentjs.com/) Created attachment 97576 [details] [review] Bug 24455: Add moment-timezone library in opac This patch adds koha-tmpl/opac-tmpl/bootstrap/lib/moment-timezone-with-data-10-year-range.min.js in order to use the moment library with timezones (https://momentjs.com/timezone/) Created attachment 97577 [details] [review] Bug 24455: Add moment-timezone library in staff This patch adds koha-tmpl/intranet-tmpl/lib/moment/moment-timezone-with-data-10-year-range.min.js in order to use the moment library with timezones (https://momentjs.com/timezone/) Created attachment 97578 [details] [review] Bug 24455: Add JS functions to format date and datetime strings This patch adds the a js-date-format.inc file on each opac and staff interface (date-format.inc whas not available as name) When you include that file in your TT, you'll get the following functions available: 1. $date(raw_date_string, options) This function parses a date string, as produced by an api call, and returns the corresponding date formatted according to 'dateformat' and 'TimeFormat' parameters. For example: // dateformat: us // timeformat: 12hr // Timezone: UTC $date('2020-03-23T15:00:00+01:00') // You will get '03/23/2020' $date('2020-03-23T15:00:00+01:00', {withtime: true}) // You will get '03/23/2020 14:00' $date('2020-03-23T15:00:00+01:00', {withtime: true, tz: 'Europe/Paris'}) // You will get '03/23/2020 15:00+01:00' Options: * dateformat: override date format as configured in staff interface (accepts also 'rfc3339') * timeformat: override time format as configured in staff client (available options are '12hr' and '24hr') * withtime: also print the time part (default false) * tz: set the timezone 2. $datetime(raw_date_string, option) The same as $date but sets withtime to true 3. $time(raw_date_string, option) The same as $datetime but shows only the time part To test you must implement and test bug 20936, where it will be used Created attachment 98625 [details] [review] Bug 24455: Add JS functions to format date and datetime strings This patch adds the a js-date-format.inc file on each opac and staff interface (date-format.inc whas not available as name) When you include that file in your TT, you'll get the following functions available: 1. $date(raw_date_string, options) This function parses a date string, as produced by an api call, and returns the corresponding date formatted according to 'dateformat' and 'TimeFormat' parameters. For example: // dateformat: us // timeformat: 12hr // Timezone: UTC $date('2020-03-23T15:00:00+01:00') // You will get '03/23/2020' $date('2020-03-23T15:00:00+01:00', {withtime: true}) // You will get '03/23/2020 14:00' $date('2020-03-23T15:00:00+01:00', {withtime: true, tz: 'Europe/Paris'}) // You will get '03/23/2020 15:00+01:00' Options: * dateformat: override date format as configured in staff interface (accepts also 'rfc3339') * timeformat: override time format as configured in staff client (available options are '12hr' and '24hr') * withtime: also print the time part (default false) * tz: set the timezone 2. $datetime(raw_date_string, option) The same as $date but sets withtime to true 3. $time(raw_date_string, option) The same as $datetime but shows only the time part To test you must implement and test bug 20936, where it will be used Typo: + var tz = (opitons&&options.tz)||def_tz; How is this related to bug 24650? It seems that it achieves the same goal without extra lib and very few lines. (In reply to Jonathan Druart from comment #10) > Typo: > + var tz = (opitons&&options.tz)||def_tz; Ups, seems I forgot to attach the patch where I fixed that.. > How is this related to bug 24650? > It seems that it achieves the same goal without extra lib and very few lines. I hadn't seen that bug.. seems this bug is previous to that one.. but the main difference is that this implementation takes into account the timezone, so if a date comes from the api with UTC timezone it will be correctly translated to your current timezone. Created attachment 99192 [details] [review] test tz (In reply to Agustín Moyano from comment #11) > (In reply to Jonathan Druart from comment #10) > > How is this related to bug 24650? > > It seems that it achieves the same goal without extra lib and very few lines. > > I hadn't seen that bug.. seems this bug is previous to that one.. but the > main difference is that this implementation takes into account the timezone, > so if a date comes from the api with UTC timezone it will be correctly > translated to your current timezone. What do you mean by correctly translated to your current timezone? Do you mean the TZ from the server? I tried this patch, with Buenos Aires in the timezone config, I see: 2020-02-18T12:46:05-03:00 02/18/2020 16:46 (current date of the server is 16:46) Created attachment 99195 [details] [review] Bug 24455: Add JS functions to format date and datetime strings This patch adds the a js-date-format.inc file on each opac and staff interface (date-format.inc whas not available as name) When you include that file in your TT, you'll get the following functions available: 1. $date(raw_date_string, options) This function parses a date string, as produced by an api call, and returns the corresponding date formatted according to 'dateformat' and 'TimeFormat' parameters. For example: // dateformat: us // timeformat: 12hr // Timezone: UTC $date('2020-03-23T15:00:00+01:00') // You will get '03/23/2020' $date('2020-03-23T15:00:00+01:00', {withtime: true}) // You will get '03/23/2020 14:00' $date('2020-03-23T15:00:00+01:00', {withtime: true, tz: 'Europe/Paris'}) // You will get '03/23/2020 15:00+01:00' Options: * dateformat: override date format as configured in staff interface (accepts also 'rfc3339') * timeformat: override time format as configured in staff client (available options are '12hr' and '24hr') * withtime: also print the time part (default false) * tz: set the timezone 2. $datetime(raw_date_string, option) The same as $date but sets withtime to true 3. $time(raw_date_string, option) The same as $datetime but shows only the time part To test you must implement and test bug 20936, where it will be used (In reply to Jonathan Druart from comment #13) > (In reply to Agustín Moyano from comment #11) > > (In reply to Jonathan Druart from comment #10) > > > How is this related to bug 24650? > > > It seems that it achieves the same goal without extra lib and very few lines. > > > > I hadn't seen that bug.. seems this bug is previous to that one.. but the > > main difference is that this implementation takes into account the timezone, > > so if a date comes from the api with UTC timezone it will be correctly > > translated to your current timezone. > > What do you mean by correctly translated to your current timezone? Do you > mean the TZ from the server? > > I tried this patch, with Buenos Aires in the timezone config, I see: > 2020-02-18T12:46:05-03:00 > 02/18/2020 16:46 > > (current date of the server is 16:46) according to the patch your uploaded, I believe you where using the code of bug 24650. I'll try to upload a patch with [DO NOT PUSH] with a test case Created attachment 99198 [details] [review] [DO NOT PUSH] Bug 24455: test timezone This is just a test.. I added the .inc file to adimn's main page To test: 1. go to Koha main page and open chrome or firefox console 2. type $datetime('2020-02-18T12:46:05Z', {tz: 'America/Argentina/Buenos_Aires'}) and you should get "02/18/2020 09:46" because America/Argentina/Buenos_Aires is -03:00 3. type $datetime('2020-02-18T12:46:05Z', {tz: 'Asia/Shanghai'}) and you should get "02/18/2020 20:46" because Asia/Shanghai is +08:00 4. type $datetime('2020-02-18T12:46:05Z') and it should be translated to your koha instance configured timezone. So, in your opinion, do we need both approaches or only one? (bug 24455 and bug 24650) I miss the real-life use case. (In reply to Jonathan Druart from comment #17) > So, in your opinion, do we need both approaches or only one? (bug 24455 and > bug 24650) I believe both do basically the same > I miss the real-life use case. https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=98630&action=diff#a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-holdsrecord.tt_sec1 In line 170, I use it to format dates retrieved from the API into datatables. I'd say this bug looks far more useful than mine in bug 24650, which only solves a single problem I had. If we are moving more towards API driven interfaces, the need to reliably parse and manipulate dates in JS is crucial. Since moment.js is the defacto way of doing this in JS, it seems by far the best way forward. I'll apply and sign this off now. Created attachment 99869 [details] [review] Bug 24455: Add moment library in opac This patch adds koha-tmpl/opac-tmpl/bootstrap/lib/moment.min.js in order to use the moment library (https://momentjs.com/) Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> Created attachment 99870 [details] [review] Bug 24455: Add moment library in staff This patch adds koha-tmpl/intranet-tmpl/lib/moment/moment.min.js in order to use the moment library (https://momentjs.com/) Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> Created attachment 99871 [details] [review] Bug 24455: Add moment-timezone library in opac This patch adds koha-tmpl/opac-tmpl/bootstrap/lib/moment-timezone-with-data-10-year-range.min.js in order to use the moment library with timezones (https://momentjs.com/timezone/) Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> Created attachment 99872 [details] [review] Bug 24455: Add moment-timezone library in staff This patch adds koha-tmpl/intranet-tmpl/lib/moment/moment-timezone-with-data-10-year-range.min.js in order to use the moment library with timezones (https://momentjs.com/timezone/) Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> Created attachment 99873 [details] [review] Bug 24455: Add JS functions to format date and datetime strings This patch adds the a js-date-format.inc file on each opac and staff interface (date-format.inc whas not available as name) When you include that file in your TT, you'll get the following functions available: 1. $date(raw_date_string, options) This function parses a date string, as produced by an api call, and returns the corresponding date formatted according to 'dateformat' and 'TimeFormat' parameters. For example: // dateformat: us // timeformat: 12hr // Timezone: UTC $date('2020-03-23T15:00:00+01:00') // You will get '03/23/2020' $date('2020-03-23T15:00:00+01:00', {withtime: true}) // You will get '03/23/2020 14:00' $date('2020-03-23T15:00:00+01:00', {withtime: true, tz: 'Europe/Paris'}) // You will get '03/23/2020 15:00+01:00' Options: * dateformat: override date format as configured in staff interface (accepts also 'rfc3339') * timeformat: override time format as configured in staff client (available options are '12hr' and '24hr') * withtime: also print the time part (default false) * tz: set the timezone 2. $datetime(raw_date_string, option) The same as $date but sets withtime to true 3. $time(raw_date_string, option) The same as $datetime but shows only the time part To test you must implement and test bug 20936, where it will be used Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> Created attachment 99874 [details] [review] Bug 24455: test timezone This is just a test.. I added the .inc file to adimn's main page To test: 1. go to Koha main page and open chrome or firefox console 2. type $datetime('2020-02-18T12:46:05Z', {tz: 'America/Argentina/Buenos_Aires'}) and you should get "02/18/2020 09:46" because America/Argentina/Buenos_Aires is -03:00 3. type $datetime('2020-02-18T12:46:05Z', {tz: 'Asia/Shanghai'}) and you should get "02/18/2020 20:46" because Asia/Shanghai is +08:00 4. type $datetime('2020-02-18T12:46:05Z') and it should be translated to your koha instance configured timezone. Created attachment 99875 [details] [review] Bug 24455: [DO NOT PUSH] test timezone This is just a test.. I added the .inc file to adimn's main page To test: 1. go to Koha main page and open chrome or firefox console 2. type $datetime('2020-02-18T12:46:05Z', {tz: 'America/Argentina/Buenos_Aires'}) and you should get "02/18/2020 09:46" because America/Argentina/Buenos_Aires is -03:00 3. type $datetime('2020-02-18T12:46:05Z', {tz: 'Asia/Shanghai'}) and you should get "02/18/2020 20:46" because Asia/Shanghai is +08:00 4. type $datetime('2020-02-18T12:46:05Z') and it should be translated to your koha instance configured timezone. Signed off on the basis of passing the tests in comment #16 Thx, Andrew! If this solves your need - should we mark bug 24650 duplicate or resolved moved? *** Bug 24650 has been marked as a duplicate of this bug. *** (In reply to Katrin Fischer from comment #28) > Thx, Andrew! If this solves your need - should we mark bug 24650 duplicate > or resolved moved? Done :) Created attachment 100119 [details] [review] Bug 24455: Add moment library in opac This patch adds koha-tmpl/opac-tmpl/bootstrap/lib/moment.min.js in order to use the moment library (https://momentjs.com/) Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Created attachment 100120 [details] [review] Bug 24455: Add moment library in staff This patch adds koha-tmpl/intranet-tmpl/lib/moment/moment.min.js in order to use the moment library (https://momentjs.com/) Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Created attachment 100121 [details] [review] Bug 24455: Add moment-timezone library in opac This patch adds koha-tmpl/opac-tmpl/bootstrap/lib/moment-timezone-with-data-10-year-range.min.js in order to use the moment library with timezones (https://momentjs.com/timezone/) Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Created attachment 100122 [details] [review] Bug 24455: Add moment-timezone library in staff This patch adds koha-tmpl/intranet-tmpl/lib/moment/moment-timezone-with-data-10-year-range.min.js in order to use the moment library with timezones (https://momentjs.com/timezone/) Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Created attachment 100123 [details] [review] Bug 24455: Add JS functions to format date and datetime strings This patch adds the a js-date-format.inc file on each opac and staff interface (date-format.inc whas not available as name) When you include that file in your TT, you'll get the following functions available: 1. $date(raw_date_string, options) This function parses a date string, as produced by an api call, and returns the corresponding date formatted according to 'dateformat' and 'TimeFormat' parameters. For example: // dateformat: us // timeformat: 12hr // Timezone: UTC $date('2020-03-23T15:00:00+01:00') // You will get '03/23/2020' $date('2020-03-23T15:00:00+01:00', {withtime: true}) // You will get '03/23/2020 14:00' $date('2020-03-23T15:00:00+01:00', {withtime: true, tz: 'Europe/Paris'}) // You will get '03/23/2020 15:00+01:00' Options: * dateformat: override date format as configured in staff interface (accepts also 'rfc3339') * timeformat: override time format as configured in staff client (available options are '12hr' and '24hr') * withtime: also print the time part (default false) * tz: set the timezone 2. $datetime(raw_date_string, option) The same as $date but sets withtime to true 3. $time(raw_date_string, option) The same as $datetime but shows only the time part To test you must implement and test bug 20936, where it will be used Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Created attachment 100124 [details] [review] Bug 24455: [DO NOT PUSH] test timezone This is just a test.. I added the .inc file to adimn's main page To test: 1. go to Koha main page and open chrome or firefox console 2. type $datetime('2020-02-18T12:46:05Z', {tz: 'America/Argentina/Buenos_Aires'}) and you should get "02/18/2020 09:46" because America/Argentina/Buenos_Aires is -03:00 3. type $datetime('2020-02-18T12:46:05Z', {tz: 'Asia/Shanghai'}) and you should get "02/18/2020 20:46" because Asia/Shanghai is +08:00 4. type $datetime('2020-02-18T12:46:05Z') and it should be translated to your koha instance configured timezone. Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Created attachment 100125 [details] [review] Bug 24455: Add Moment.js to About page Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> WARNING: This must NOT be pushed before I have a better clarity of the needs. This does not need to be pushed before one of the 2 dependent bugs anyway. See for instance bug 24608 comment 26. (This bug does not need to be marked as blocked, the dep is the other way around) I'm facing similar challenges here as I did with bug 24454. Now I'm wrapping my head around it, there seems to be a fair bit of duplicate code introduced here that already exists in koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc I'm by no means against introducing moment.js, I like the idea of using well maintained and thought out third party libraries and the was of accessing the functions written here is nice and elegant.. much like the way you introduced elegant accessors for currency handling in bug 24454 (I'd like to see some of those idea's taken forward too). But.. I don't like that we're duplicating logic and making it somewhat less clear which functions should be used for the job so would like some form of merge/aggregation of such functionality and a clear documentation somewhere for how to use it before I'm happy pushing this. Examples on things that need clarifying.. 1) Is the intention to always pass in a 'String' (and if so, of what format) to the new $date, $datetime and $time window functions.. or are you deliberately allow Date prototypes to be passed? 2) You allow to pass in a timezone in the options, but the string value may also include an offset if it's a RFC3339 so how are the two being ratified..? I'd be tempted to have some clearer function names.. like fromkohadate which would take a syspref formatted date string and return a moment prototype and tokohadate which would take a moment and return a string formatted per koha sysprefs ? (In reply to Martin Renvoize from comment #39) > I'm facing similar challenges here as I did with bug 24454. > > Now I'm wrapping my head around it, there seems to be a fair bit of > duplicate code introduced here that already exists in > koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc > > I'm by no means against introducing moment.js, I like the idea of using well > maintained and thought out third party libraries and the was of accessing > the functions written here is nice and elegant.. much like the way you > introduced elegant accessors for currency handling in bug 24454 (I'd like to > see some of those idea's taken forward too). > > But.. I don't like that we're duplicating logic and making it somewhat less > clear which functions should be used for the job so would like some form of > merge/aggregation of such functionality and a clear documentation somewhere > for how to use it before I'm happy pushing this. Hello Martin, functions in calendar.inc has similar logic, but they do the oposite job of this functions. calendar.inc function's inputs are date/datetime strings as specified by dateformat preference and returns a JS Date object. This function's inputs are date/datetime string as returned from the api (RFC3339) and returns a date/datetime/time string as specified by dateformat preference, and translated to corresponding timezone. (In reply to Agustín Moyano from comment #42) > (In reply to Martin Renvoize from comment #39) > > I'm facing similar challenges here as I did with bug 24454. > > > > Now I'm wrapping my head around it, there seems to be a fair bit of > > duplicate code introduced here that already exists in > > koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc > > > > I'm by no means against introducing moment.js, I like the idea of using well > > maintained and thought out third party libraries and the was of accessing > > the functions written here is nice and elegant.. much like the way you > > introduced elegant accessors for currency handling in bug 24454 (I'd like to > > see some of those idea's taken forward too). > > > > But.. I don't like that we're duplicating logic and making it somewhat less > > clear which functions should be used for the job so would like some form of > > merge/aggregation of such functionality and a clear documentation somewhere > > for how to use it before I'm happy pushing this. > > Hello Martin, functions in calendar.inc has similar logic, but they do the > oposite job of this functions. > > calendar.inc function's inputs are date/datetime strings as specified by > dateformat preference and returns a JS Date object. > > This function's inputs are date/datetime string as returned from the api > (RFC3339) and returns a date/datetime/time string as specified by dateformat > preference, and translated to corresponding timezone. I believe Calendar.inc functions are used to get a date from tt variable, and put that date into a jquery calendar input. This functions should be used to format dates from the api (In reply to Martin Renvoize from comment #40) > Examples on things that need clarifying.. > > 1) Is the intention to always pass in a 'String' (and if so, of what format) > to the new $date, $datetime and $time window functions.. or are you > deliberately allow Date prototypes to be passed? It was designed to transform dates from the api, so input is always RFC3339 > 2) You allow to pass in a timezone in the options, but the string value may > also include an offset if it's a RFC3339 so how are the two being ratified..? For example, if you pass the following value '2020-03-18T07:00:00-03:00' and you set the timezone for an equivalent of +03:00 the result of calling $datetime should be '2020-03-18T13:00:00+03:00' each one being equivalent to '2020-03-18T10:00:00Z' I'm looking to add a followup of my own here to clarify the situation.. struggled to put it into words when talking to Agustin so I'm going to let code speak ;) Created attachment 101708 [details] [review] Bug 24455: Add moment library in opac This patch adds koha-tmpl/opac-tmpl/bootstrap/lib/moment.min.js in order to use the moment library (https://momentjs.com/) Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Created attachment 101709 [details] [review] Bug 24455: Add moment library in staff This patch adds koha-tmpl/intranet-tmpl/lib/moment/moment.min.js in order to use the moment library (https://momentjs.com/) Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Created attachment 101710 [details] [review] Bug 24455: Add moment-timezone library in opac This patch adds koha-tmpl/opac-tmpl/bootstrap/lib/moment-timezone-with-data-10-year-range.min.js in order to use the moment library with timezones (https://momentjs.com/timezone/) Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Created attachment 101711 [details] [review] Bug 24455: Add moment-timezone library in staff This patch adds koha-tmpl/intranet-tmpl/lib/moment/moment-timezone-with-data-10-year-range.min.js in order to use the moment library with timezones (https://momentjs.com/timezone/) Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Created attachment 101712 [details] [review] Bug 24455: Add JS functions to format date and datetime strings This patch adds the a js-date-format.inc file on each opac and staff interface (date-format.inc whas not available as name) When you include that file in your TT, you'll get the following functions available: 1. $date(raw_date_string, options) This function parses a date string, as produced by an api call, and returns the corresponding date formatted according to 'dateformat' and 'TimeFormat' parameters. For example: // dateformat: us // timeformat: 12hr // Timezone: UTC $date('2020-03-23T15:00:00+01:00') // You will get '03/23/2020' $date('2020-03-23T15:00:00+01:00', {withtime: true}) // You will get '03/23/2020 14:00' $date('2020-03-23T15:00:00+01:00', {withtime: true, tz: 'Europe/Paris'}) // You will get '03/23/2020 15:00+01:00' Options: * dateformat: override date format as configured in staff interface (accepts also 'rfc3339') * timeformat: override time format as configured in staff client (available options are '12hr' and '24hr') * withtime: also print the time part (default false) * tz: set the timezone 2. $datetime(raw_date_string, option) The same as $date but sets withtime to true 3. $time(raw_date_string, option) The same as $datetime but shows only the time part To test you must implement and test bug 20936, where it will be used Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Created attachment 101713 [details] [review] Bug 24455: [DO NOT PUSH] test timezone This is just a test.. I added the .inc file to adimn's main page To test: 1. go to Koha main page and open chrome or firefox console 2. type $datetime('2020-02-18T12:46:05Z', {tz: 'America/Argentina/Buenos_Aires'}) and you should get "02/18/2020 09:46" because America/Argentina/Buenos_Aires is -03:00 3. type $datetime('2020-02-18T12:46:05Z', {tz: 'Asia/Shanghai'}) and you should get "02/18/2020 20:46" because Asia/Shanghai is +08:00 4. type $datetime('2020-02-18T12:46:05Z') and it should be translated to your koha instance configured timezone. Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Created attachment 101714 [details] [review] Bug 24455: Add Moment.js to About page Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Created attachment 101715 [details] [review] Bug 24455: (follow-up) Document function This patch just adds some minimal documentation to the main exported JS function. Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Back to PQA.. I've added a followup which documents the main function. I'm happy to add moment.js as it's not a huge library and is pretty much the defacto library used in the wild for datetime manipulation. I still think it's somewhat unclear how Calendar.inc and this include differ from the end developers perspective and would love to see something akin to 'date_inputs.inc' and 'date_outputs.inc' to make it clear how the two relate to each other.. and perhaps even have some of the functionality shared. I'll try to work out some followup bugs for these parts however. Nice work everyone! Pushed to master for 20.05 enhancement not backported to 19.11.x (In reply to Martin Renvoize from comment #54) > I'm happy to add moment.js as it's not a huge library and is pretty much the > defacto library used in the wild for datetime manipulation. But deprecated. See bug 30310. |