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

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')

Related

display a firebase timestamp in relative format using moment & react

I'm trying to display a timestamp from firebase in a relative format.
Within my firebase collection I have:
author (string): lechnerio
comment (string): Test Comment is here!
createdAt (timestamp): 22 November 2022 at 13:47:06 UTC+1
and I'd like to display the timestamp in a realtive way, e.g.: 31 minutes ago
{author} schreibt am
{moment(new Date(createdAt.nanoseconds), "YYYYMMDD").fromNow()}:
{comment}
What I'm getting back with the exact same values from above:
lechnerio schreibt am 53 years ago:
Test comment is here!
when just using new Date(createdAt) instead an invalid Date get's returned. Any suggestions on how to fix this issue. Thanks a lot in advance!
I found an answer to my issue.
{moment(createdAt.seconds * 1000).fromNow()}
In addition to the issue I was also struggling to convert english localisation to german, so "5 minutes ago" are supposed to be "vor 5 Minuten".
import moment from 'moment'
import localization from 'moment/locale/de'
moment.updateLocale("de", localization)
{moment(createdAt.seconds * 1000).fromNow()}

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

Moment.js time wrong when DST is on

Don't understand why the examples on moment-timezone page give me different result than what they say they should.
Running these statements give me date with my current local time for each instance:
var jun = moment("2014-06-01T12:00:00Z");
var dec = moment("2014-12-01T12:00:00Z");
jun.tz('America/Los_Angeles').format('ha z'); // 5am PDT **I get 7am**
dec.tz('America/Los_Angeles').format('ha z'); // 4am PST **I get 6am**
What am I missing?
Found the issue was due to missing time zone data. After loading time zone data I get the expected results, below; how to load time zone data
[http://momentjs.com/timezone/docs/#/data-loading/][1]

Querying dates in Realm React Native

[EDITED]
I'd like to query and filter by dates in realm. Here's my code:
let factories = realm.objects('Factory')
for(factory of factories) {
let toys = realm.objects('Toy').filtered('factory_id == factory.id')
let lowerBound = new Date(year + '-1-1T00:00:00Z')
let uppperBound = new Date(year + '-2-1T00:00:00Z')
let janToys = toys.filtered('created_at > lowerBound AND created_at < uppperBound')
}
year is a variable declared before the code snippet above.
This doesn't work and I'm pretty sure it's because the date format is not correct.
Here is the date format when I log toys:
Fri Mar 24 2017 16:01:59 GMT+0800 (Malay Peninsula Standard Time)
I'd like to know how to query realm dates. I can't find it in the documentation and other posts here. I'd appreciate any help. If this is not a date format issue, please tell me.
Thank you!
EDIT: I added the outside loop. This may not be a date format issue. Here is the error message:
Error: Predicate expressions must compare a keypath and another keypath or a constant value`
It seems that Realm does not support dot operators inside its queries. Forcing Realm to be relational is not allowed. As a solution, I transformed my usage to follow NoSQL convention. Passing in objects instead of declaring relationships.

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