Skip to content

This action sets the current ISO8601 time to the time output and also provides readableTime, formattedTime, and many more digital outputs like year, day, second, etc. Useful for setting build times in subsequent steps, renaming your artifact, or keeping the same recorded time for the entire workflow.

License

Notifications You must be signed in to change notification settings

automediaAI/get-rounded-time

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace
 
 

Repository files navigation

Test the action workflow codecov GitHub release GitHub marketplace

Get Rounded Time Github Action

This action sets the current ISO8601 time to the time output and also provides readableTime, formattedTime, and many more digital outputs like year, day, second, etc. Useful for setting build times in subsequent steps, renaming your artifact, or keeping the same recorded time for the entire workflow. If you specify an interval and interval type, it'll round off the time to that value. Essentially, it integrates the Get Current Time Action with this time rounding off code.

Inputs

format

Time format to use - using MomemtJS format syntax - optional

utcOffset

UTC offset to use - using MomemtJS utcOffset syntax - optional

interval

Interval by which to round off the time - 5, 10, 15, 30 etc - optional

intervalType

Type of Interval - minutes, hours, seconds - Refer to moment.duration docs for all available formats. - optional

method

Rounding method, floor, ceil .... (It supports all the round methods available in NodeJS Math package) - optional

Outputs

time

The ISO time this action was run, not affected by the parameter utcOffset e.g. '2020-01-01T00:30:15.000Z'

ISOTime

Same as time

readableTime

Human-friendly time - affected by the parameter utcOffset e.g. 'Wed Jan 01 2020 08:30:15 GMT+0800'

formattedTime

The time this action was run - formatted using format and utcOffset inputs

fancyTime

The time this action was run - formatted 'MMM Do YYYY'

year,month,day,hour,minute,second,millisecond

Digital outputs, just as names

Example usage

steps:
  - name: Get rounded time
    uses: automediaAI/get-rounded-time@v2
    id: rounded-time
    with:
      format: YYYYMMDD-HH
      utcOffset: "+08:00"
      interval: 15
      intervalType: minutes
      method: ceil
  - name: Use rounded time
    env:
      TIME: "${{ steps.rounded-time.outputs.time }}"
      R_TIME: "${{ steps.rounded-time.outputs.readableTime }}"
      F_TIME: "${{ steps.rounded-time.outputs.formattedTime }}"
      YEAR: "${{ steps.rounded-time.outputs.year }}"
      DAY: "${{ steps.rounded-time.outputs.day }}"
    run: echo $TIME $R_TIME $F_TIME $YEAR $DAY

Run locally

First

npm install

Test

npm test

And you'll see the console output as following:


PASS ./action.test.js

  action

     Should load (2 ms)

     Should run with basic functionality (2 ms)

     Should run with format (1 ms)

     Should run with other basic outputs (1 ms)

     Should pass format inputs (1 ms)

     Should throw error (1 ms)

File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 100 100 100 100
action.js 100 100 100 100

Test Suites: 1 passed, 1 total

Tests: 6 passed, 6 total

Snapshots: 0 total

Time: 2.50 s

Ran all test suites.


Build

npm start

And you'll see the index.js is generated in the dist folder

About

This action sets the current ISO8601 time to the time output and also provides readableTime, formattedTime, and many more digital outputs like year, day, second, etc. Useful for setting build times in subsequent steps, renaming your artifact, or keeping the same recorded time for the entire workflow.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%