Neurotic Pink Mongooses

    @endran/testdate
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    testdate

    pipeline status coverage report npm version

    Keeping dates in test date fresh and relevant.

    Description

    Whenever you have are developing an application that involves dynamic behaviour based on time you run into issues with stale test dates. You need to have dates in your test data, but wever now and then tests may fail due to dates going over some threshold. Those days are gone!
    With testdate you can make all your dates in testing relative to now. No limitations of file types, as long as it's plain text.

    Installation

    npm install @endran/testdate --save

    or

    yarn add @endran/testdate

    Usage

    Before you seed your database solution with test data run:

    testdate \
        --source myTestData.augmented.csv \
        --destination myTestData.csv \
        --format "YYYY-MM-DD HH:mm:ss"

    This will scan the --source file for keywords, and output fresh data to --destination. See https://devhints.io/moment for all --format options. Use --override an existing destination file, by default it will not override anything. If you want you can use punctuation marks around your data, for example when working with JSON it's nice to wrap testdate in "...", use --marks to denote the amount of marks that need to be removed.

    Keywords

    The --source file will be scanned for keywords. You modify dates relative to now, and you can also fix time of day. It's also possible to override formatting for a specific date.

    With fixed time and custom format : __TESTDATE_now-0000-01-00@19:00:00#dddd, MMMM Do YYYY_TESTDATE__...

    Everything between __TESTDATE_ and _TESTDATE__ will be considered, folowing these requirements:

    • Starts with either now+ or now-, to indicate to add or substract time relative to now.
    • Required after now, continues with date:
      • First years, YYYY (required).
      • Then months, MM.
      • Then days, DD.
    • Optionally for time, either; T for time relative to now; Or @ for fixed time of day.
      • Hours, HH.
      • Minutes, mm.
      • Seconds, ss.
    • Optionally, to add custom format for a single line, append with #<yourFormat>.
    • Optionally, to add punctuation marks for a single line, append with %<numberOfMarks>.
      • Even if you do not need custom formatting you do need to add the # token, use like #%<numberOfMarks>.
    • Each date instance must be on a single line, it may not span 2 lines.

    Example:

    Input:

    Now                                 : __TESTDATE_now+0000_TESTDATE__...
    Now (LL)                            : __TESTDATE_now+0000#LL_TESTDATE__...
    Now in epoch seconds                : __TESTDATE_now+0000@19:00:00#X_TESTDATE__...
    Today at 19                         : __TESTDATE_now+0000@19:00:00_TESTDATE__...
    
    Plus 1 month and 5 minutes          : __TESTDATE_now+0000-01-00T00:05:00_TESTDATE__...
    Minus 1 month and 5 minutes         : __TESTDATE_now-0000-01-00T00:05:00_TESTDATE__...
    
    +10 Years                           : __TESTDATE_now+0010_TESTDATE__...
    With + 5 Months                     : __TESTDATE_now+0010-05_TESTDATE__...
    With +10 Days                       : __TESTDATE_now+0010-05-10_TESTDATE__...
    With +3 Hours                       : __TESTDATE_now+0010-05-10T03_TESTDATE__...
    With +22 Minutes                    : __TESTDATE_now+0010-05-10T03:22_TESTDATE__...
    With +16 Seconds                    : __TESTDATE_now+0010-05-10T03:22:16_TESTDATE__...
    With Custom Format (LL)             : __TESTDATE_now-0000-01-00T00:05:00#LL_TESTDATE__...
    With Fixed Time (19h)               : __TESTDATE_now-0000-01-00@19:00:00_TESTDATE__...
    With fixed time and custom format   : __TESTDATE_now-0000-01-00@19:00:00#dddd, MMMM Do YYYY_TESTDATE__...
    With punctuation                    : "__TESTDATE_now-0000-01-00@19:00:00#%1_TESTDATE__"...
    With formatting and punctuation     : "__TESTDATE_now-0000-01-00@19:00:00#LL%1_TESTDATE__"...
    
    Multiple per line                   : __TESTDATE_now-0000-01-00@19:00:00#dddd, MMMM Do YYYY_TESTDATE__, and another; __TESTDATE_now+0000_TESTDATE__
    

    Output for testdate --source exampleInput.txt --destination exampleOutput.txt -O -F llll, ran in CET timezone:

    Now                                 : Fri, Dec 28, 2018 11:17 AM...
    Now (LL)                            : December 28, 2018...
    Now in epoch seconds                : 1546021027...
    Today at 19                         : Fri, Dec 28, 2018 7:17 PM...
    
    Plus 1 month and 5 minutes          : Mon, Jan 28, 2019 11:22 AM...
    Minus 1 month and 5 minutes         : Wed, Nov 28, 2018 11:12 AM...
    
    +10 Years                           : Mon, Dec 18, 2028 9:23 AM...
    With + 5 Months                     : Fri, May 18, 2029 9:23 AM...
    With +10 Days                       : Mon, May 28, 2029 9:23 AM...
    With +3 Hours                       : Mon, May 28, 2029 12:23 PM...
    With +22 Minutes                    : Mon, May 28, 2029 12:45 PM...
    With +16 Seconds                    : Mon, May 28, 2029 12:45 PM...
    With Custom Format (LL)             : November 18, 2018...
    With Fixed Time (19h)               : Sat, Nov 17, 2018 5:00 AM...
    With fixed time and custom format   : Saturday, November 17th 2018...
    With punctuation                    : Sat, Nov 17, 2018 5:00 AM...
    With formatting and punctuation     : November 18, 2018...
    
    Multiple per line                   : Saturday, November 17th 2018, and another; Tue, Dec 18, 2018 9:35 AM
    

    Help

    Options:
      -V, --version             output the version number
      -S, --source <path>       Required. Location the source data.
      -D, --destination <path>  Required. Location of output.
      -F, --format <string>     Required. Format of the output.
      -O, --override            Optional. If set will override any existing destination file.
      -M, --marks <number>      Optional. Number of punctuation marks around test date. (default: 0)
      -Z, --zone                Optional. Set timezone.
      -h, --help                output usage information

    See https://momentjs.com/ for more details on formatting and timezones.

    License

    Copyright (c) 2020 David Hardy
    Copyright (c) 2020 codecentric nl

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

    Install

    npm i @endran/testdate

    DownloadsWeekly Downloads

    125

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    25.7 kB

    Total Files

    10

    Last publish

    Collaborators

    • endran