How to parse "YY/MM/DD" strings using the Translator Framework?

20 views
Skip to first unread message

Shel

unread,
Jan 3, 2016, 11:34:21 AM1/3/16
to zotero-dev

Hi,

I’m trying to write a translator for a website with the Translator Framework, but I’m not very familiar with Javascript. The date string I get on the website is likeyy/MM/DD, I need to do something to parse it, or reformat it at least. Is it possible to use some utility library, like Moment.js, within the framework? What is the elegant way to deal with this kind of date format with basic javascript?

FW.Scraper({
  itemType         : 'report',
  detect           : FW.Url().match(/detail/),
  title            : FW.Xpath('//XPATH').text().trim(),

  // the date string got here is formatted 'YY/MM/DD':
  date             : FW.Xpath('//XPATH').text().match(/[\d\/]+/),
});

Thanks

Sebastian Karcher

unread,
Jan 3, 2016, 12:24:42 PM1/3/16
to zoter...@googlegroups.com
No libraries, no, not even in regular Zotero translators.

Zotero can parse dates quite well and YYYY/MM/DD would work nicely. How
to solve this depends on the database. If it's all post 2000, you can
just .prepend("20") and be done with it. Otherwise, you'd have to use a
hook to do explicitly what the YY format expects the user to do
implicitly, i.e. something like testing for whether it's >20 and in that
case prepend 19, otherwise prepend 20.

On 01/03/2016 05:10 AM, Shel wrote:
>
> Hi,
>
> I’m trying to write a translator for a website with the Translator
> Framework <https://www.zotero.org/support/dev/translators/framework>,
> but I’m not very familiar with Javascript. The date string I get on
> the website is like|yy/MM/DD|, I need to do something to parse it, or
> reformat it at least. Is it possible to use some utility library, like
> Moment.js, within the framework? What is the elegant way to deal with
> this kind of date format with basic javascript?
>
> |FW.Scraper({ itemType : 'report', detect : FW.Url().match(/detail/),
> title : FW.Xpath('//XPATH').text().trim(), // the date string got here
> is formatted 'YY/MM/DD': date :
> FW.Xpath('//XPATH').text().match(/[\d\/]+/), }); |
>
> Thanks
>
> ​
> --
> You received this message because you are subscribed to the Google
> Groups "zotero-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to zotero-dev+...@googlegroups.com
> <mailto:zotero-dev+...@googlegroups.com>.
> To post to this group, send email to zoter...@googlegroups.com
> <mailto:zoter...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/zotero-dev.
> For more options, visit https://groups.google.com/d/optout.

Shel

unread,
Jan 6, 2016, 11:35:14 PM1/6/16
to zotero-dev
Got it. I did some consulting and the simple prepend would work for me. Thanks Adam!

adamsmith於 2016年1月4日星期一 UTC+8上午1時24分42秒寫道:
Reply all
Reply to author
Forward
0 new messages