Unknow HTML date format "1615856400000" = "Thuesday, Mar 16, 2021", "1615770000" = "Thuesday, Mar 15, 2021" etc - html

I'm web scraping a HTML page which shows a time series generated by a function inside a <script> tag. On the webbpage I can see different dates for the time series, but when I "view page source" these dates seem to be converted into numbers.
For example "1615856400000" = "Thuesday, Mar 16, 2021", "1615770000" = "Monday, Mar 15, 2021" and "1612227600000" = "Thuesday, Feb 2, 2021".
Does anyone know what the logic is for these conversions? Ideally I would like a list which shows the mappings per day, starting at some arbitrary date e.g. "Wednesday, Feb 26, 2014".

Related

JSON string to date with Javascript in Google Apps Script editor

I am working through w3schools, particularly https://www.w3schools.com/js/js_json_parse.asp
I ran this example and got an unexpected result
let dashText = '{ "name":"John", "birth":"1986-12-14", "city":"New York"}';
let objD = JSON.parse(dashText);
console.log("objD: ", objD);
objD.birth = new Date(objD.birth);
console.log("objD.birth: ", objD.birth);
3:09:04 PM Info objD: { name: 'John', birth: '1986-12-14', city: 'New York' }
3:09:04 PM Info objD.birth: Sat Dec 13 1986 18:00:00 GMT-0600 (Central Standard Time)
Note the difference in the dates. I then changed the dashes to slashes out of curiosity and the date was correctly determined from the string.
let slashText = '{ "name":"John", "birth":"1986/12/14", "city":"New York"}';
let objS = JSON.parse(slashText);
console.log("objS: ", objS);
objS.birth = new Date(objS.birth);
console.log("objS.birth: ", objS.birth);
3:09:04 PM Info objS: { name: 'John', birth: '1986/12/14', city: 'New York' }
3:09:04 PM Info objS.birth: Sun Dec 14 1986 00:00:00 GMT-0600 (Central Standard Time)
Can anyone explain the results?
Javascript parses DateTime strings differently based on how the string is formatted. The dashes are parsed to ISO date, i.e. international time. You can see this when it tries to handle the timezone conversion, where it sets the time to 18:00:00 to account for the 6 hour shift from Universal Time. Slashes are parsed as just the date, and doesn't try to adjust the time based on timezones.
Here's a w3schools link that goes over this in more detail.

How to render correct datetime in hugo post?

I created a post using hugo new posts/mypost.md and it created mypost.md for me with header toml configuration like that
But, when i run on server (local), the datetime rendered wrong like:
How can I fix that?
Thanks in advance!
This is how I got it to work:
Add your date format in config.toml
[params]
dateFormat = "02 Jan 2006"
Your post should contain the date in its front-matter:
---
date: "2020-12-23T15:21:54+05:30"
...
---
Use the format in your layout:
<div>{{ .Params.date.Format .Site.Params.dateFormat }}</div>
Note: Please DO NOT change the numbers in the date format. It must be 02 for day, Jan for month, 2006 for year, etc. check this for more details.
Check also Hugo 0.87 (Aug. 2021, two years later), which comes with:
a timezone
a timedate format
{{ time.Format "Monday, Jan 2, 2006" "2015-01-21" }}
→
"Wednesday, Jan 21, 2015"
Note that since Hugo 0.87.0, time.Format will return a localized string for the current language.
Date/time formatting layouts
{{ .Date | time.Format ":date_long" }}
The full list of custom layouts with examples for English:
:date_full => Wednesday, June 6, 2018
:date_long => June 6, 2018
:date_medium => Jun 6, 2018
:date_short => 6/6/18
:time_full => 2:09:37 am UTC
:time_long => 2:09:37 am UTC
:time_medium => 2:09:37 am
:time_short => 2:09 am
In Hugo v0.95.0 (released 16 Mar 2022), it should be
[params]
date_format = "02 Jan 2006"
with
---
date: 2022-03-18T21:10:00+07:00
---
in the post front matter, where double quote marks are not necessary. I used Ananke theme.
Setting the date_format in the config file seems weird to me. I would set the following in the config file:
defaultContentLanguage: nl
languageCode: nl_NL
These are variables that do NOT go into params, but on the root level of the config file. When you have these you can simply call:
{{ .Date | time.Format ":date_long" }}
or... if you need another format:
{{ .Date | time.Format ":date_medium" }}
The date will be formatted in your language.
You need to set dateformat in file config.toml at 2.1.2006 (any proper format, ensure 2, Jan, 2006).
This link save my day

Change date format in my HTML / CSS output

Have a dates saved in my sqlite database in this format 2019-01-24 13:41:40.515955 and when I output to my web page its displayed as 2019-01-24 13:41:40 UTC. Please can I get guidance on displaying something like Wed 24 January 2019 ? No sure how to approach it
Use Javascript, would be a simple approach to parse and format dates with desired output.
var date = new Date('6/29/2011 4:52:48 PM UTC');
date.toString() // "Wed Jun 29 2011 09:52:48 GMT-0700 (PDT)"
var date = new Date('6/29/2011 4:52:48 PM UTC');
date.toString() // "Wed Jun 29 2011 09:52:48 GMT-0700 (PDT)"
console.log(`Year: ${date.getFullYear()}, Month: ${date.getMonth()}, Day, ${date.getDay()}`)
You can also parse dates using Date.parse(``);

Padding a csv value with 0's

I have this csv file that I would like to sort on the 20th and 21st field. For example the data in those fields are P1,PK5. My challenge is that when I sort on those fields they are not in order as I would have liked. It seems like I have to pad those fields to the longest value in that fields data.
OrderNum,MerrillRecipientID,CustomerClass,MerrillItemNum,PODTemplateID,GridCode,AetnaDocID,MemberID,FirstName,MI,LastName,Address1,Address2,Address3,City,State,Zip,Country,OEL,PalletNum,PckgNum,IMBCode,ProcDate
"M394993","M39499300010000001","0GH","3GH000503","PDP","BO","1011250","MEBB04CB","Name","","Name","address","","","City","SC","29170-2043","","*******AUTO**SCH 5-DIGIT 29033","P1","PK5","2031100094470495539729170204309","3GH000503","August 26, 2013"
"M394993","M39499300010000002","0GH","3GH000503","PDP","BO","1011572","MEBB07GB","Name","G","Name","address","","","City","SC","29020-2912","","*********AUTO**SCH 3-DIGIT 290","P1","PK1","3031100094470495580529020291210","3GH000503","August 26, 2013"
"M394993","M39499300010000003","0GH","3GH000503","PDP","BO","1011693","MEBB08MP","Name","B","Name","address","","","City","SC","29061-9447","","*********AUTO**SCH 3-DIGIT 290","P1","PK2","3031100094470495583729061944757","3GH000503","August 26, 2013"
"M394993","M39499300010000004","0GH","3GH000503","PDP","BO","1011751","MEBB097M","Name","A","Name","address","","","City","SC","29645-0433","","*************AUTO**3-DIGIT 296","P1","PK31","3031100094470495629629645043333","3GH000503","August 26, 2013"
"M394993","M39499300010000005","0GH","3GH000503","PDP","BO","1012075","MEBB0K4L","Name","E","Name","address","","","City","SC","29682-9634","","*************AUTO**3-DIGIT 296","P1","PK33","3031100094470495637929682963428","3GH000503","August 26, 2013"
"M394993","M39499300010000006","0GH","3GH000503","PDP","BO","1012437","MEBB0TWQ","Name","R","Name","address","","","City","SC","29505-3030","","*******AUTO**SCH 5-DIGIT 29501","P1","PK24","2031100094470495556429505303050","3GH000503","August 26, 2013"
"M394993","M39499300010000007","0GH","3GH000503","PDP","BO","1012750","MEBB0YJY","Name","L","Name","address","","","City","SC","29642-3006","","***********AUTO**5-DIGIT 29642","P1","PK38","2031100094470495567529642300601","3GH000503","August 26, 2013"
So from the above data I need to have the file look like so:
OrderNum,MerrillRecipientID,CustomerClass,MerrillItemNum,PODTemplateID,GridCode,AetnaDocID,MemberID,FirstName,MI,LastName,Address1,Address2,Address3,City,State,Zip,Country,OEL,PalletNum,PckgNum,IMBCode,ProcDate
"M394993","M39499300010000001","0GH","3GH000503","PDP","BO","1011250","MEBB04CB","Name","","Name","address","","","City","SC","29170-2043","","*******AUTO**SCH 5-DIGIT 29033","P1","PK05","2031100094470495539729170204309","3GH000503","August 26, 2013"
"M394993","M39499300010000002","0GH","3GH000503","PDP","BO","1011572","MEBB07GB","Name","G","Name","address","","","City","SC","29020-2912","","*********AUTO**SCH 3-DIGIT 290","P1","PK01","3031100094470495580529020291210","3GH000503","August 26, 2013"
"M394993","M39499300010000003","0GH","3GH000503","PDP","BO","1011693","MEBB08MP","Name","B","Name","address","","","City","SC","29061-9447","","*********AUTO**SCH 3-DIGIT 290","P1","PK02","3031100094470495583729061944757","3GH000503","August 26, 2013"
"M394993","M39499300010000004","0GH","3GH000503","PDP","BO","1011751","MEBB097M","Name","A","Name","address","","","City","SC","29645-0433","","*************AUTO**3-DIGIT 296","P1","PK31","3031100094470495629629645043333","3GH000503","August 26, 2013"
"M394993","M39499300010000005","0GH","3GH000503","PDP","BO","1012075","MEBB0K4L","Name","E","Name","address","","","City","SC","29682-9634","","*************AUTO**3-DIGIT 296","P1","PK33","3031100094470495637929682963428","3GH000503","August 26, 2013"
"M394993","M39499300010000006","0GH","3GH000503","PDP","BO","1012437","MEBB0TWQ","Name","R","Name","address","","","City","SC","29505-3030","","*******AUTO**SCH 5-DIGIT 29501","P1","PK24","2031100094470495556429505303050","3GH000503","August 26, 2013"
"M394993","M39499300010000007","0GH","3GH000503","PDP","BO","1012750","MEBB0YJY","Name","L","Name","address","","","City","SC","29642-3006","","***********AUTO**5-DIGIT 29642","P1","PK38","2031100094470495567529642300601","3GH000503","August 26, 2013"
the P1 field could be P100 and so I would need to pad P1 to P001. But really it justs need to be whatever the max length is. I can sort the file on the two fields but not sure how to pad them.
Thanks in advance for your help.
okay, since nothing else has been forthcoming, here's a quick python (2.x or 3.x) script which will do what you need:
import sys
import csv
reader = csv.reader(sys.stdin)
writer = csv.writer(sys.stdout, quoting=csv.QUOTE_ALL)
rows = [row for row in reader]
max_len = max([len(row[20]) for row in rows[1:]])
writer.writerow(rows[0])
for row in rows[1:]:
while len(row[20]) < max_len:
row[20] = 'PK0' + row[20][2:]
writer.writerow(row)
if you save this as, say, pad.py, then you can use it like so:
$ cat /path/to/my_csv_file.csv | python /path/to/pad.py > /path/to/my_new_csv_file.csv
and will create my_new_csv_file.csv in the format you need. Since the script acts on stdin and outputs to stdout, you can use it in many different ways to suit your purposes.
Hope this helps.

finding the d3.extent of an array with dates to create xScale in D3

I am trying to create a focus brush, similar to this http://bl.ocks.org/mbostock/1667367, using a json file.
I am having a problem to correctly read the date and create the xScale for the chart.
Say these are some of the dates in my Json file, extracted into an array.
//some dates
dates = ["Fri Jul 27 22:32:59 2012","Fri Jul 27 22:33:59 2012","Fri Jul 27 22:34:59 2012","Fri Jul 27 22:35:59 2012","Fri Jul 27 22:36:59 2012"];
//declare new date variable
var dates2 =[];
var format = d3.time.format("%a %b %d %H:%M:%S %Y");
dates.forEach(function(d){
dates2.push(format.parse(d));
});
console.log(d3.extent(dates_extents));
dates_extents = d3.extent(dates2);
x.domain(d3.extent(dates_extents);
x2.domain(x.domain);
Althought the dates_extents is printed in the console, I get this error:
TypeError: n.map is not a function [Break On This Error] ...t,n)},n.copy=function(){return ae(t)},n}function oe(t){return t.innerRadius}func... d3.v3.min.js (line 1)
Any ideas what might be the source of the problem and how I can solve it?
Thanks!