Firefox Bookmarks add_date - date

One question to firefox exported bookmarks.
How to read this date: ADD_DATE="1375088003"? I think it is date when user add new website to bookmarks but how to read this all string? Where is year, day and month?

It's the Epoch time, ie the number of seconds since Jan 1 1970. To convert it to a human-friendly date, you can pass it through the 'date' unix command:
date -r 1375088003
will return
Mon 29 Jul 2013 18:53:23 AEST
(on my trusty Mac here in eastern Australia, hence the AEST)

Here's what I do. I export bookmarks from my browser. Assume the result file is called "bookmarks.html". I have a one-line executable script that takes a file as input, and creates another file with many long fields stripped. The one-liner I call "icon.sed" contains this:
sed 's/ICON=\"[^\"]*\"//' | sed 's/ICON_URI=\"[^\"]*\"//' | \
sed 's/LAST_CHARSET=\"[^\"]*\"//' | sed 's/HREF=\"[^\"]*\"//'| \
tr -s ' '
I use it like this:
~/icon.sed <bookmarks.html >newbook.txt
I have another script that takes a mm/dd/ccyy parameter, and returns the Epoch time for that date. That executable script is called "epoch.sh":
#!/bin/sh
if [ -z "$1" ]; then echo "You must supply a date"
else date -j -f "%m/%d/%Y" "$1" "+%s"; fi
exit 0
Choose a date you're looking for, and send it through "epoch.sh", such as: ~/epoch.sh 10/30/2015 which outputs this: 1446246082 .
You can then grep your newbook.txt file looking for either ADD_DATE or LAST_MODIFIED date which begins with the first four digits: 1446
grep 'LAST_MODIFIED="1446' newbook.txt
Also, use epoch.sh to get a pair of epoch times for start and stop dates so you can bracket your results by doing multiple greps over the range, using just the first four digits of each epoch time.

To convert a Firefox timestamp to a date with BASIC:
If the timestamp is from an sqlite dump of places.sqlite, you need to truncate it first:
stg0 = Left("1670163289502000", 10) results in "1670163289"
Convert the timestamp:
Dim var0 As double, var1 As Date
var0 = stg0
or
var0 = "1670163289" 'BASIC will do the conversion for you
var1 = (var0 / 86400) + 25569
where 86400 is the # of seconds in a day and 25569 is the BASIC daynumber for 1/1/1970

Related

unix date command with nanosecond precision. Input parameter

I'm having difficulty parsing an inputted date with nanosecond precision:
date: invalid date `15-OCT-18 12:40:01:000203570 AM'
Yet when I drop the nanoseconds, it works fine:
$ date -d "15-OCT-18 12:40:01 AM" +"%d-%m-%Y %H:%M:%S %p"
15-10-2018 00:40:01 AM
Looking the docs its suggests uppercase N is to be used for ns
Even when I drop the Ns it generates the ns for me
$ date -d "15-OCT-18 12:40:01 AM" +"%d-%m-%Y %H:%M:%S:%N %p"
15-10-2018 00:40:01:000000000 AM
Should be in the format
date -d "15-OCT-18 12:40:01.000203570 AM" +"%d-%m-%Y %H:%M:%S:%N %p"
Data needs to have . instead of : spearating seconds and ns
You need to replace the : before the Nanoseconds identifier with .(dot)
> date -d"$(echo "15-OCT-18 12:40:01:000203570 AM" | sed 's/:/./3')" +"%d-%m-%Y %H:%M:%S.%N %p"
15-10-2018 00:40:01.000203570 AM
>

red/rebol: Subtracting dates returns days, how can I change that?

Playing with the date type, I was wondering, why a subtraction always returns days, how can I make it return minutes (or seconds, etc.), which could be possible in the second example
>> 24-dec-2016 - now
== 82
>> 24-dec-2016/0:00 - now
== 82
is that just arbitrary or can I influence what is returned? I tried around a bit with refinements, but would appreciate a push in a direction, the rebol/red way.
Maybe there is a more substantial thing below that question: what's the "rule" of what a subtraction returns, common sense, some kinda discussion and agreement or is it just determined by who implements it? (e.g. the result of subtracting: 1.1.1.1 - 1, 200x200 - 100, ...)
You can use difference:
difference 24-dec-2016 now
== 1952:06:01
To get specific parts, use path syntax:
time-diff: difference 24-dec-2016 now
time-diff/2
Gives the minutes (the second component)
== 1951:42:11
== 42
✓ Check out Francois Vanzeveren's Date-Time Script on REBOL.org
If you load it, i.e.,
do http://www.rebol.org/download-a-script.r?script-name=date-time.r
then you can do this:
>> ? date-dif
USAGE:
DATE-DIF date1 date2 /y /m /d /ym /md /yd
DESCRIPTION:
Returns the difference between two dates.
DATE-DIF is a function value.
ARGUMENTS:
date1 -- (Type: date)
date2 -- (Type: date)
REFINEMENTS:
/y -- Returns the number of complete years between #date1
and #date2.
/m -- Returns the number of complete months between #date
1 and #date2.
/d -- Returns the number of complete days between #date1
and #date2.
/ym -- Returns the number of full months between #date1 a
nd #date2,
not including the difference in years.
/md -- Returns the number of full days between #date1 and
#date2,
not including the difference in months.
/yd -- Returns the number of full days between #date1 and
#date2,
not including the difference in years.
✓ >> ? now to see the /refinements for dates
>> ? now
USAGE:
NOW /year /month /day /time /zone /date /weekday /yearday
/precise
DESCRIPTION:
Returns the current local date and time.
NOW is a native value.
REFINEMENTS:
/year -- Returns the year only.
/month -- Returns the month only.
/day -- Returns the day of the month only.
/time -- Returns the time only.
/zone -- Returns the time zone offset from GMT only.
/date -- Returns date only.
/weekday -- Returns day of the week as integer (Monday is
day 1).
/yearday -- Returns day of the year (Julian)
/precise -- Use nanosecond precision
Example:
>> d: 27-7-1973
== 27-Jul-1973
>> d/day
== 27
>> d/month
== 7
>> d/year
== 1973

Finding start and end date from given year and month in Unix

I have a unix script named myScript where two arguments should be passed in YYYYMM format indicating starting month and ending month for the script.
Inside the script, based on the argument, I need to calculate the start date of the month in first argument and the end date of the month in second argument.
I wrote the below code:
startYr=`expr substr $2 1 4`
startMonth=`expr substr $2 5 2`
startDate=`cal $startMonth $startYr | grep . | fmt -1 | tail -1`
endYr=`expr substr $3 1 4`
endMonth=`expr substr $3 5 2`
endDate=`cal $endMonth $endYr | grep . | fmt -1 | tail -1`
export eomStartDate=$startYr-$startMonth-$startDate
export eomEndDate=$endYr-$endMonth-$endDate
echo "START DATE: $eomStartDate"
echo "END DATE: $eomEndDate"
However, on running above script as:
myScript 201401 201412
The result I am getting is:
START DATE: 2014-12-31
END DATE: --31
What am I missing ? I am using Korn Shell.
Thanks for reading!
The parameters should be $1 and $2, not $2 and $3. Also, for start date you should do sed -n 10p to get the 10th line, from where the days start.

How can reorder a file by asc or desc order from specific column

How can reorder a file by asc or desc order from specific column date and time or only date column.
{"hostname":"sg2","role":"epay","eventid":"ALERT_ORACLE","date":"02/08/2011","time":"01:30:00"},
{"hostname":"sg1","role":"pay","eventid":"ALERT_DF","date":"11/24/2010","time":"19:33:01"},
{"hostname":"sg3","role":"ipay","eventid":"ALERT_SMF","date":"12/11/2012","time":"02:30:00"},
Usually use "sort -gk (column number)" in that case not able to catch date and time column or only date, maybe is need some separator string or related.
Expetected view is:
{"hostname":"sg1","role":"pay","eventid":"ALERT_DF","date":"11/24/2010","time":"19:33:01"},
{"hostname":"sg2","role":"epay","eventid":"ALERT_ORACLE","date":"02/08/2011","time":"01:30:00"},
{"hostname":"sg3","role":"ipay","eventid":"ALERT_SMF","date":"12/11/2012","time":"02:30:00"},
Your life would be easier if you had chosen an ISO date format (YYYY-mm-dd), but
sort_by_date() {
awk -F \" '{
split($16, date, "/")
split($20, time, ":")
timestamp = mktime(date[3]" "date[1]" "date[2]" "time[1]" "time[2]" "time[3])
print timestamp "\t" $0
}' "$1" |
sort -k1,1n |
cut -f2-
}
sort_by_date filename
For descending, use sort -k1,1nr
Use sort with : as delimiter and order by column 5M for date comparison:
$ sort -t: -k5M file
{"hostname":"sg1","role":"pay","eventid":"ALERT_DF","date":"11/24/2010","time":"19:33:01"},
{"hostname":"sg2","role":"epay","eventid":"ALERT_ORACLE","date":"02/08/2011","time":"01:30:00"},
{"hostname":"sg3","role":"ipay","eventid":"ALERT_SMF","date":"12/11/2012","time":"02:30:00"},
Source: Sort logs by date field in bash.

How to match date mm/dd/yyyy

Given the following input
506028500,1820196768,43,0,84552257, ,1,-71.16,42.42,04/26/2012,
I want to filter the date at the end of the row, so I can change its mm/dd/yyyy format into MySQL date format yyyy-mm-dd:
I am trying to match the date at the end of the row having first removed the trailing ',' (comma).
{
s/,$//g
/\([0-9][0-9]\)\/\([0-9][0-9]\)\/\([0-9][0-9][0-9][0-9]\)$/=
}
I'm getting 12847, but am expecting 04262012.
What am I doing wrong, that I can't even match the date that's there?
Thanks.
This might work for you:
echo "506028500,1820196768,43,0,84552257, ,1,-71.16,42.42,04/26/2012," |
sed 's|,\(..\)/\(..\)/\(....\),$|,\3-\2-\1,|'
506028500,1820196768,43,0,84552257, ,1,-71.16,42.42,2012-26-04,
If you just want the date:
echo "506028500,1820196768,43,0,84552257, ,1,-71.16,42.42,04/26/2012," |
sed 's|.*,\(..\)/\(..\)/\(....\),$|\3-\2-\1|'
2012-26-04
This works for me:
sed "s/\([0-9]\{2\}\)\/\([0-9]\{2\}\)\/\([0-9]\{4\}\)$/\3-\1-\2/g" someFile.txt
At least it replaces the date string with one of the desired format.
To only print the date at the end, the following works for me:
sed "s/.*\([0-9]\{2\}\)\/\([0-9]\{2\}\)\/\([0-9]\{4\}\)$/\3-\1-\2/g" someFile.txt