Closed jun6lee closed 11 months ago
const APPLE_EPOCH_START = new Date("2001-01-01").getTime(); --- been able to dig out that Apple does a weird thing with EPOCH timestamps, so start with this
and feed the ZANNOTATIONMODIFICATIONDATE or ZANNOTATIONCREATIONDATE something like this:
modifiedAt: convertAppleTime(r.modifiedAt),
createdAt: convertAppleTime(r.createdAt),
where we covert as follows:
function convertAppleTime(appleTime) {
return new Date(APPLE_EPOCH_START + appleTime * 1000).getTime();
}
@jun6lee sure, you can DIY you template, please visit: https://github.com/bingryan/obsidian-ibook-plugin#for-user-defined-templates
I'm not familiar enough with TypeScript, but what I'm after are two additional fields:
I have done No.3 in my template. -- but the convertAppleTime logic I don't know the syntax to achieve in ts.
last_highlight: -- which I would like to be the latest instance of ZANNOTATIONMODIFICATIONDATE [0] of sorted array, I guess
and
highlight_count: which would be an integer of how many highlights are imported it'd need a count of how many times the {{#if ZANNOTATIONSELECTEDTEXT}} gets a result.
@jun6lee metadata
---
book: {{library.ZSORTTITLE}}
author: {{library.ZAUTHOR}}
language: {{library.ZLANGUAGE}}
last_opened: {{date ZLASTOPENDATE "YYYY/MM/DDTHH:mm:ss" }}
last_highlight: {{date ZANNOTATIONMODIFICATIONDATE "YYYY/MM/DDTHH:mm:ss "}}
tags:
- highlights/iBooks
---
# π Book: {{library.ZSORTTITLE}}
**Author**:: {{library.ZAUTHOR}}
**LANGUAGE**:: {{library.ZLANGUAGE}}
**Book Link**:: [Apple Books Link](ibooks://assetid/{{library.ZASSETID}})
{{#if library.ZBOOKDESCRIPTION}}
---
# π§Ύ Description
{{{library.ZBOOKDESCRIPTION}}}
{{/if}}
---
# π How I Discovered IT
{{#group annotation by="ZFUTUREPROOFING5"}}
- π{{value}}
{{#each items}}
{{#if ZANNOTATIONSELECTEDTEXT}}
{{#is ZANNOTATIONSTYLE 5}}
- π― <mark style="background: #C4B3D9;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{#is ZANNOTATIONSTYLE 4}}
- π― <mark style="background: #E6A5AB;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{#is ZANNOTATIONSTYLE 3}}
- π― <mark style="background: #EDD570;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{#is ZANNOTATIONSTYLE 2}}
- π― <mark style="background: #A8BADE;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{#is ZANNOTATIONSTYLE 1}}
- π― <mark style="background: #B0D17F;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{#is ZANNOTATIONSTYLE 0}}
- π― <mark style="background: #E65747;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{/if}}
{{#if ZANNOTATIONNOTE}}
- βοΈ{{ZANNOTATIONNOTE}}
{{/if}}
{{/each}}
{{/group}}
Oh, didn't know it's that simple.. works! Super!!!
Actually, it fixed formatting, but the dates are wrong.
Last Highlighted: {{date annotation.ZANNOTATIONCREATIONDATE "YYYY/MM/DD HH:mm:ss "}} always seems to reflect the time imported into obsidian rather than the time it was highlighted/modified
@jun6lee
I found that the time field in ibook is similar:
ZLASTOPENDATE: 703830839.572769
ZPURCHASEDATE: 695628940.302915
ZANNOTATIONCREATIONDATE: 610881340.480055
ZANNOTATIONMODIFICATIONDATE: 610881340.480137
703830839.572769
I do not understand what format is used to store time
It is Apple's Cocoas variation on EPOCH which starts from: 1 January 2001
Standard Epoch time starts from: 1 January 1970 00:00:00 UTC
For this reason need to add on 978307200 seconds somehow. Refer: https://www.epochconverter.com/coredata
It is Apple's Cocoas variation on EPOCH which starts from: 1 January 2001
Standard Epoch time starts from: 1 January 1970 00:00:00 UTC
For this reason need to add on 978307200 seconds somehow. Refer: https://www.epochconverter.com/coredata
@jun6lee nice job, very very very very useful information π«‘
@jun6lee update this plugin and try again. :)
last_opened: {{dateFormat library.ZLASTOPENDATE "YYYY/MM/DDTHH:mm:ss" }}
Super. Does the trick.
{{dateFormat ZANNOTATIONMODIFICATIONDATE "YYYY/MM/DD HH:mm:ss" }}
also works...
Something out of your hands, but an Apple quirk I noticed was that if I highlight on my iPhone or iPad, the modification date will only update to when the update gets uploaded to iCloud and then re-downloaded on macOS.
Will have to live with that. Using below instead:
Highlighted: {{dateFormat ZANNOTATIONCREATIONDATE "YYYY/MM/DD HH:mm:ss" }}
Very cool plugin, adding some notes on improving, if it's possible.
Is there a way of getting these details in too?
1) & 2) - Under the book title and language, I'd like to see these two things: last_highlight: {{latest instance of ZANNOTATIONMODIFICATIONDATE}} highlight_count: {{number of records per book}}
If you could have a look
3) Add on each highlight: Highlighted: {{ZANNOTATIONMODIFICATIONDATE}}
You are pulling this, but it will needs some logic to convert it to readable data. Looking into it, will report back.
My Template: