Could someone please tell me that I am stupid beca...
# suitescript
m
Could someone please tell me that I am stupid because there is a better way to get the local datetime than this?
Copy code
let timeRecord = record.load({
  id: 1,
  type: "customrecord_currenttime",
  isDynamic: true,
});
let now = format.format({
  value: new Date(timeRecord.getValue("custrecord_currenttime_now")),
  type: format.Type.DATETIME,
  timezone: format.Timezone.ASIA_RIYADH,
});
let nowParts = now.split("/");
now = nowParts[1] + "/" + nowParts[0] + "/" + nowParts[2];
now = new Date(now);
a
pretty sure that is NOT going to give you local dateTIME you're splitting and new Date is gonna give you midnight at the date so you're stupid 😂 seriously though I'm not 100% sure what you're trying to accomplish just flip the date from MM/DD/YY to DD/MM/YY??
m
No,
nowParts[2]
includes the time.
just flip the date from MM/DD/YY to DD/MM/YY??
I found out that I need to do this yeah.
a
this is a serverside script?
m
Yeah
a
and you want a string? or is a dateObj ok? i figured based on locale settings the ui will display any timestamps per the user's settings?
m
so you're stupid 😂
I would be seriously happy if there is a better way 😂 , not sure why I have to go through this pain.
dateObj
The UI displays the time correctly, but the one you get in the script is different.
a
...
ok waht? lol then what are you trying to get to?
m
I am running a search task to save a CSV file, that will be requested by the clients system later.
a
okay...
m
So, I want to save the output of the saved search (filtered on a specific date) into a path like "..../2023/Sep/6.csv"
So, I need to get the date right.
a
hmm can you not just use ISO string date if you want a file name that is consistent and sorts nicely in a file list?
and is timezone agnostic 🙂
m
They are not agnostic 🤣
They will want it in local time I guess.
But thanks 🙏
b
depends on what you want from the Date, parsing the Date twice, once in a different timezone, makes 2 different Dates
for example the time of
new Date(timeRecord.getValue("custrecord_currenttime_now"))
is not equal to the time of
new Date(now);
a
I'm still not really clear what it is you're needing.... dates in JS can be annoying, lots of ppl use libraries for dates, but depending on your use case there may be a way to simplify it either using NS format module, or just js date fucntions
and to be perfectly honest, as ugly/annoying as you find your solution, if it works, it works 😄
m
I used to get the local time this way.
You set a Dynamic Default to the field to be
Current Date/Time
But the country changed it's timezone.
But Oracle didn't update that in their code I guess.
I can change it to another country, that would give the correct one. But I am kind of afraid to do that.
a
"the country changed its timezone" ?
you mean like daylight savings?
timezones should account for that already
m
Daylight savings is done in certain seasons, right?
a
right, but if you're setting the zone based on a location rather than a numeric offset from UTC then it should be accounted for
m
It is not that, the clock increased by 1 hour in the whole year.
a
!!!
m
We have exactly the same time as the country beside us right now.
LOL
a
really? where? which counryt?
Saudi?
m
It is a crazy country, man.
Egypt
a
huh
m
Egypt used to be behind SaudiArabia by 1 hour. Now we are exactly the same.... while it is not actually the same time in the day of course.
Madness 😂
a
so wouldn't you use
AFRICA_CAIRO: 'Africa/Cairo'
m
That would give the wrong time.
Check the code.
a
or you were doing that and now its wrong?
m
I am using
Timezone.ASIA_RIYADH
a
when did this change happen?
I saw that, why i guessed saudi 🙂
m
A few months ago.
LOL, then that's why Oracle didn't adjust it.
Because it is crazy.
c
They reinstated Daylight Saving Time in April?
a
hmm so a quick goodle said egypt started using DST again
c
Maybe Luxon or another library is updated to recognize this change
m
Will check it, thanks
a
yeah just be mindful that your "fix" doesn't break again in like 6 weeks or whatever 😂
1
seriously consider just using UTC time for everything that's system rather than user interface
☝️ 1
m
That's why I thought adjusting it on SaudiArabia is better.
a
saudi doesn't have DST, so when egypt flips back it will be wrong again
...its not even 6 weeks, its like 3 weeks
just ignore it for 3 more weeks, then you have 6 months to figure it out 😄
m
I don't understand why you are saying 3 weeks.
Nothing will change, they will stay on UTC+03:00
a
the time will change back to GMT+2 on the last Thursday in September... according to google
m
No, that won't happen
a
so they decided in March 2023, that they would start doing DST from April to September... .. but you're saying since then they decided actually let's just stay on this timezone forever?
m
That's my understanding yeah.
a
... and google doesn't know about it yet?
m
Why would google care about Egypt anyway?
a
lol google care about ALL THE INFO 🙂
but yeah I guess maybe english language google might not care
m
Kidding, I just don't expect the info to be true.
I will check the local news.
a
wikipedia?
m
Sorry, I feel I drove you crazy.
🙃 1
a
ROFL timezones make all devs crazy... always have 😄
😢 1
😄 2
m
I didn't meet a single person who knows this.
I will check it. Thanks very much.
a
👍
c
ROFL timezones make all devs crazy... always have
Just wait for interplanetary browsers...
Good luck @Marwan!
🙏 1
a
I was actually thinking thats the most exciting part about colonizing mars... we can switch to just using stardate or something no timezones 😂
💯 1
c
please please please