LoginSignup
1
0

More than 1 year has passed since last update.

Cloud Workflows で YYYYMMDD 形式の文字列を得る

Posted at

Background

Google Cloud Platform (GCP) のサービスの一つ Cloud Workflows を利用する機会がありました。その際、ワークフロー内の特定のステップにおいて、引数に YYYYMMDD 形式の文字列が必要となったので、 標準ライブラリを利用したスタンドアローンな実装の一例をこちらに(備忘録として)記録しておきます。

TL;DR

# 標準ライブラリ 用途 実行後の例
1 sys.now 現在時刻の UNIX 時間を取得する 1651647916.8227115
2 time.format UNIX 時間を日時の形式( ISO 8601 )に変換する 2022-05-04T16:05:16.822711+09:00
3 text.substring 日付部分( YYYY-MM-DD )を取得する 2022-05-04
4 text.replace_all - を削除する 20220504

Example

main:
    steps:
    - extractCurrentTimestamp:
        call: sys.now
        result: currentTimestamp

    - formatCurrentTimestamp:
        call: time.format
        args:
            seconds: ${currentTimestamp}
            timezone: 'Asia/Tokyo'
        result: currentDatetime

    - substrCurrentDatetime:
        call: text.substring
        args:
            source: ${currentDatetime}
            start: 0
            end: 10
        result: currentDate

    - removeHyphen:
        call: text.replace_all
        args:
            source: ${currentDate}  
            substr: '-'
            repl: ''
        result: result

    - showResult:
        call: sys.log
        args:
            data: ${result}

Summary

Cloud Workflows をトリガーする際に YYYYMMDD 形式の文字列を引数として動的に引き渡すことが面倒な場合に、このような処理を記述することで簡単に実現することができます(そのようなケースがあれば、の話ですが...)。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0