回答編集履歴

2

文言を修正

2023/10/12 01:37

投稿

akira777
akira777

スコア8

test CHANGED
@@ -1,56 +1 @@
1
- import {GetObjectCommand,S3Client} from '@aws-sdk/client-s3';
2
- const client = new S3Client({})
3
-
4
- export const handler = async(event) => {
5
-
6
- const command = new GetObjectCommand({
7
- Bucket: "abcd-test01-system",
8
- Key: "calendar/test2023.txt"
9
- });
10
-
11
- console.log(JSON.stringify(event))
12
-
13
- const data = await client.send(command);
14
- const operationTime = await data.Body.transformToString();
15
- var lines = operationTime.split('\n');
16
-
17
- // メント削除及び余分な空白削除
1
+ V2からV3にードを変更したが正常に動作しません。
18
- lines = lines.map( line => {
19
- return line.replace(/#[\s\S]*$/g, '').replace(/\s+$/g, '');
20
- });
21
-
22
- // 無効(空白)行の削除
23
- lines = lines.filter( line => {
24
- return line != '';
25
- });
26
-
27
- // 時間内かどうかのチェック
28
- const IsOperationTime = CheckInTime(lines);
29
-
30
- return { IsOperationTime: IsOperationTime };
31
- }
32
-
33
- function CheckInTime(lines) {
34
- // 現在時間
35
- const now = new Date();
36
- const month = now.getMonth() + 1;
37
- const day = now.getDate();
38
-
39
- // 祝日指定の抽出
40
- const holidays = lines.filter(line => {
41
- return line.split(',')[0].split('/').length == 2;
42
- });
43
-
44
- // 祝日チェック
45
- let flg = true;
46
- holidays.forEach( line => {
47
- const tmp = line.split(',');
48
- const date = tmp[0].split('/');
49
- if(date.length == 2){
50
- if(month == date[0] && day == date[1]){
51
- flg = false;
52
- }
53
- }
54
- })
55
- return flg;
56
- }

1

修正

2023/10/12 01:36

投稿

akira777
akira777

スコア8

test CHANGED
@@ -1,6 +1,3 @@
1
- 下記コードで自己解決しました。
2
- --------------------------------------------------------------------------------------------------
3
-
4
1
  import {GetObjectCommand,S3Client} from '@aws-sdk/client-s3';
5
2
  const client = new S3Client({})
6
3