Data::Sah::Compiler::js::TH::date - js's type handler for type "date"


This document describes version 0.87 of Data::Sah::Compiler::js::TH::date (from Perl distribution Data-Sah-JS), released on 2016-09-14.


Unlike in perl compiler where the date type can be represented either as int (epoch), DateTime object or Time::Moment object, in js compiler we only represent date with the Date object.

Date() accept various kinds of arguments, including:

  • Date()

    Current date.

  • Date(milliseconds epoch)

  • Date(year, month, date, hour, minute, sec, millisec)

    But year is 114 utk 2014, month=0 for January.

  • Date(datestring)

    This saves us from doing date parsing ourselves.

  • Date(another Date object)

But note that if the arguments are invalid, Date() will still return a Date object, but if we try to do d.getMonth() or d.getYear() it will return NaN. This can be used to check that a date is invalid: isNaN(d.getYear()) or simply <isNaN(d)>.

To compare 2 Date object, we can use d1 > d2, d1 < d2, but for anything involving equality check, we need to prefix using +, +d1 === +d2.


Please visit the project's homepage at


Source repository is at


Please report any bugs or feature requests on the bugtracker website

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.


perlancar <>


This software is copyright (c) 2016 by

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.