Moment.js format issue with en-gb locale - momentjs

moment.locale("en")
moment().format("LT") -> 1:21 PM
but
moment.locale("en-gb")
moment().format("LT") -> 13:21
which is incorrect.
Here's the reproduction sandbox: https://codesandbox.io/s/moment-js-time-format-issue-rnr9vc
Looks like a bug. How do I fix this?

Related

Utilities.formatDate() gives wrong date/time

I read a cell in a google sheet which is a date (it reads it correctly) and then I attempt to reformat it using the Utilities.formatDate() method. All I really want to do is drop the "minutes" from the time so it looks like:
9/11/2023 10:02 am
In debug mode, the date is correct when read, but the formatDate method gives the wrong results.
I looked at timezone in both Sheets and AppScript - and there is no way to make them the same (that I see) because the list of choices is different in the two platforms. Not sure what to do.
I am trying to use GMT-4 Eastern Standard Time / New York which I can do fine in app script but there is no such one listed in Google Sheets.
Any advice would be welcome
You can probably resolve you issue with just formatting the cell. Using information from here
Here's a simple script with same date and different formats
function lfunko() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet0");
sh.getRange("A1:D1").setValue(new Date()).setNumberFormats([["mm/dd/yy hh:mm:ss", "mm/dd/yyyy hh:mm", "mm/dd/yyyy hh:mm AM/PM","mmm dd, yyyy hh:mm am/pm"]]);
}
A
B
C
D
09/11/22 16:43:40
09/11/2022 16:43
09/11/2022 04:43 PM
Sep 11, 2022 04:43 PM

I'm not getting the start of and end of day in MomentJS

When I run this;
console.log(moment().startOf('day'))
console.log(moment().endOf('day'))
I get this:
2022-02-17T16:00:00.000Z
2022-02-18T15:59:59.999Z
Today is 18th Feb 2022 in my local time. How do I get 2022-02-18T00:00:00.000Z as startof and 2022-02-18T23:59:59.999Z as endof? Thanks

Dayjs format with timezone abbreviation i.e. 'z' like in moment.js

Trying to migrate from Moment.js to Dayjs but the only thing I can't get working is the Timezone abbreviation.
dayjs('2020-07-06T14:30:00.000-04:00').tz(dayjs.tz.guess()).format('Do MMM YYYY [at] HH:MMa z')
Calling the above I would expect 6th Jul 2020 at 08:07am EDT but currently I am just getting z where EDT is.
I have added the utc and timezone plugins and can't see any other plugins needed to make this work, I notice on Dayjs format docs that z isn't listed but searching the web, I see a lot of folks saying the solution is format('', {timeZone}) but the format doesn't take a second argument??
Looks like it was added to tz-plugin: https://github.com/iamkun/dayjs/pull/325/files#diff-cad460a5e46a2a48c59e95356c683820R195
Here's a code sandbox with an example of the issue:
https://codesandbox.io/s/hungry-knuth-r58gz
--- Edit
Looks like support for tz abbr was removed :(
https://github.com/iamkun/dayjs/pull/448/commits/e64c03cea79c579bcd3c4caf235b4724e56614d4
The z formatting option is added in 1.9.0 version of dayjs: https://github.com/iamkun/dayjs/pull/1069
Update the newest version and set up the plugins correctly, which should work. Example below:
var dayjs = require("dayjs")
var utc = require("dayjs/plugin/utc")
var timezone = require("dayjs/plugin/timezone")
var advanced = requires("dayjs/plugin/advancedFormat")
dayjs.extend(timezone)
dayjs.extend(utc)
dayjs.extend(advanced)
dayjs().tz('Europe/Paris').format('DD/MM/YYYY z')

Convert into am / pm in Impala

Like in a similar query on this forum I need, but I need it to work in Impala:
In a workaround my colleague and myself attempted the following:
-- combine start date and time into a datetime
-- impala can't handle am/pm so need to look for pm indicator and add 12 hours
-- and then subtract 12 hours if it's 12:xx am or pm
================
t1.appt_time,
hours_add(
to_timestamp(concat(to_date(t1.appt_date),' ',t1.appt_time),'yyyy-MM-dd H:mm'),
12*decode(lower(strright(t1.appt_time,2)),"pm",1,0) -
12*decode(strleft(t1.appt_time,2),'12',1,0)
) as appt_datetime,
t1. ...
=========
Has anybody an easier and more elegant approach ?
Your workaround is valid, Impala does currently support AM/PM formatting for dates. There are a few open issues related
https://issues.apache.org/jira/browse/IMPALA-3381
https://issues.apache.org/jira/browse/IMPALA-5237
https://issues.apache.org/jira/browse/IMPALA-2262

splunk mysearchbar.timerange.val() datetime to UTC

I am using Splunk 6.2.X along with Django bindings to create a Splunk app.
To get access to the earliest/latest dates from the timerange picker, am using the following in my JS.
mysearchbar.timerange.val()
Am getting back a map where the values are in epoch format:
Object {earliest_time: 1440122400, latest_time: 1440124200}
When I convert them using moment using the following, I get different datetime than expected:
> moment.unix('1440122400').utc().toString()
"Fri Aug 21 2015 02:00:00 GMT+0000"
However, the time does not correspond to the values that have been selected on the time range picker i.e. 08/20/2015 22:00:00.000
Am not sure what the difference is getting caused by? Am sure tht the timezone is not the factor as the time difference is erratically not equivalent to derive using simple timezone add/subtract.
I was wondering if this behaviour can be explained as to how to get the Splunk epoch datetime to UTC would be helpful.
I was able to get rid of the timezone issue by performing the following:
Setting the timezone of the Splunk engine to UTC in props.conf as follows:
TZ = GMT
Setting up the CentOS (the server hosting Splunk) to UTC
Hope this helps anyone else who stumbles upon similar issues.
Thanks.

Resources