日付におけるスマート バリューの使用例

Jira Automation テンプレート ライブラリでスマート バリューを使用する方法をご確認ください。

スマート バリューを使用して、createdupdatedduedateresolutiondate といった日付を操作、フォーマットできます。

これらの関数はスマート バリューをサポートするフィールド内の日付ピッカー カスタム フィールド ({{issue.MyDateFieldName}} または {{issue.customfield_12356}} など) でも使用できます。

日付の操作とフォーマットで利用可能なスマート バリューをご覧ください

日付をフォーマットする

スマート バリューの末尾の日付でフォーマットを指定できます (以下を参照)。使用可能な日付フォーマットを見る

1 2 3 4 5 6 // using inbuilt formats {{issue.resolutiondate.asLongDateTime}} {{issue.MyDateFieldName.longDateTime}} {{issue.created.jqlDateTime}} {{issue.created.mediumTime}} {{issue.Sprint.endDate.jiraDate}} - format the Sprint field's end date into a format suitable to set another field
1 2 3 // Or, you can specify the format {{issue.dueDate.format("dd/MM/yyyy")}} {{issue.created.as("dd MMM")}}

ロケール (位置に基づく日付形式)

日付を表示するロケールを指定します (初期設定は「US」ロケール)。

1 2 // Prints the issue's created date in French {{issue.created.withLocale("fr").asLongDateTime}}
1 2 // Prints the issue's created date in French Canadian {{issue.created.locale("fr_CA").longDateTime}}
1 2 // Prints the issue's created date in the locale of the reporter {{issue.created.locale(issue.reporter.locale).longDateTime}}

ロケールのリストは、Java ドキュメントを参照してください

タイム ゾーン

初期設定では、日付は「UTC」タイムゾーンで表示されます。別のタイムゾーンを指定する方法は以下のとおりです。

1 2 3 // Converts the issue's created time to the new timezone, // e.g. 10am UTC converts to 8pm AEST {{issue.created.convertToTimeZone("Australia/Sydney")}}
1 2 3 // Converts the issue's created time to the new timezone and keeps the same // times/dates. E.g. 10am UTC changes to 10am AEST {{issue.created.setTimeZone("Australia/Sydney")}}

タイムゾーンのリストは、Java ドキュメントを参照してください

ユーザーのタイムゾーンを指定する

1 2 // Prints the issue's created time in the reporters timezone. {{issue.created.convertToTimeZone(issue.reporter.timeZone)}}

日付の操作

日付の一部を設定するか、そこから値を加算または減算することで日付を操作します。

1 2 // Add 7 days to the current time {{now.plusDays(7)}}
1 2 3 // You can also chain functions // Set the created date to November 1st {{issue.created.withDayOfMonth(1).withMonth(11)}}

日付属性

日付内の個々の属性 (月など) を取得します。

1 2 // Get today's day of the month {{now.dayOfMonth}}
1 2 // Get the day of the week the issue was created {{issue.created.dayOfWeekName}}
1 2 // Get the day name of the week in French {{issue.created.locale("fr").dayOfWeekName}}

営業日の計算

現在の日付から営業日を増減するか、現在の日付に最も近い営業日を見つけます。営業日は月曜日から金曜日の 9 - 18 時とします。

1 2 // The next business day {{now.toBusinessDay()}}
1 2 // The next business day after 3 days {{now.plusDays(3).toBusinessDay()}}
1 2 // The previous business day {{now.toBusinessDayBackwards()}}
1 2 // Adds 6 business days to today {{now.plusBusinessDays(6)}}
1 2 // The first business day of the month {{now.firstBusinessDayOfMonth}}
1 2 // The last business day of the month {{now.lastBusinessDayOfMonth}}
1 2 // The number of business days beeween when the issue was created and today {{now.diff(issue.created).businessDays}}

2 つの日付の差異を計算する

diff メソッドを使用し、別の日付に渡してから測定する単位を指定することで、2 つの日付の差異を計算します。

1 2 // Gets how many hours since an issue was created {{now.diff(issue.created).hours}}
1 2 // Gets the number of days between two dates {{now.diff(issue.created).days}}
1 2 // To show positive dates use the "abs" method {{now.diff(issue.<date field>).days.abs}}

2 つの日付を比較する

2 つの指定された日付を比較しします。これらのメソッドは、別の日付をパラメーターとして取得します。

1 2 // Returns "true" {{now.isAfter(issue.created)}}

詳細な比較条件を使用して、日付を比較します。

テキストを日付に変換する

日付がテキストの場合 (changelog 内など)、日付はテキストとして保存されます。

1 {{issue.summary.toDate}}

正しいフォーマットの場合、テキストを日付に変換します。パラメーターを追加することで、どのフォーマットから変換するかを指定できます。

以下の例では、テキスト (「2020 02 15」など) を日付オブジェクトに変換します。

1 {{issue.summary.toDate("yyyy MM dd")}}

テキストを日付オブジェクトに変換した後に、フィールドの変更など、そのオブジェクトをさらに変換する必要がある場合があります (例: 日付の変更をリッスンする場合)。

1 {{fieldChange.fromString.toDate.plusDays(1).longDate}}

現在の日付/時刻を参照する

現在の日付や時間は、{{now}} を使用して参照できます。

1 2 // 1st of May this year {{now.startOfMonth.withMonth(5)}}
1 2 // 1st of May next year {{now.startOfMonth.withMonth(5).plusYears(1)}}
1 2 // last day of May {{now.withMonth(5).endOfMonth}}
1 2 // first business day in May {{now.withMonth(5).firstBusinessDayOfMonth}}
1 2 // last business day in May {{now.withMonth(5).lastBusinessDayOfMonth}}

その他のヘルプ