GORMでtime型をするときの注意

GORMでtime型をするときの注意

GORMで構造体をマイグレーションしたときに 以下のようにしてもtime型にはならなかった、、、

type test struct {
BreakTime                  *time.Time               `gorm:"type:time;comment:休憩時間"`
}

↓ マイグレすると

create table test
(
    break_time                   timestamp with time zone,
);

となった、

どうも、「time」のあとにスペースを入れれば解決するみたい。

READ MORE

時間の取り扱い方

time型を取得する

time.Time型の変数を取得する方法。

現在時刻から取得する

fmt.Println(time.Now())
// Output: 
// 2009-11-10 23:00:00 +0000 UTC

日付から取得する

fmt.Println(time.Date(2014, time.December, 31, 12, 13, 24, 0, time.UTC))
// Output:
// 2014-12-31 12:13:24 +0000 UTC
loc, _ := time.LoadLocation("Asia/Tokyo")
fmt.Println(time.Date(2014, 12, 31, 8, 4, 18, 0, loc))
// Output:
// 2014-12-31 08:04:18 +0900 JST

文字列から取得する

t, _ := time.Parse("2006-01-02", "2014-12-31")
fmt.Println(t)
// Output:
// 2014-12-31 00:00:00 +0000 UTC
t, _ := time.Parse("2006-01-02 15:04:05 MST", "2014-12-31 12:31:24 JST")
fmt.Println(t)
// Output:
// 2014-12-31 12:31:24 +0900 JST

Unix TimeStampから変換

fmt.Println(time.Unix(1419933529, 0))
// Output:
// 2014-12-30 09:58:49 +0000 UTC

第2引数でナノ秒を指定できる。

READ MORE

UIButtonの文字の設定

UIButtonの文字の設定

ボタンの設定

UIButton をコード上で使用することで、ボタンを追加することができます。 追加する時に、各状態になった場合のボタンのタイトル、色などを指定することができます。

//ボタンの宣言
UIButton *button = [[UIButton alloc]init];

//タイトル・テキスト色・画像 通常
[button setTitle:@"ボタン" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"image"] forState:UIControlStateNormal];

//タイトル・テキスト色・画像 押下中
[button setTitle:@"押下中" forState:UIControlStateHighlighted];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
[button setImage:[UIImage imageNamed:@"image"] forState:UIControlStateHighlighted];

//タイトル・テキスト色・画像 選択中
[button setTitle:@"選択中" forState:UIControlStateSelected];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
[button setImage:[UIImage imageNamed:@"image"] forState:UIControlStateSelected];

//タイトル・テキスト色・画像 無効中
[button setTitle:@"無効" forState:UIControlStateDisabled];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateDisabled];
[button setImage:[UIImage imageNamed:@"image"] forState:UIControlStateDisabled];

//フォントサイズ
[button.titleLabel setFont:[UIFont systemFontOfSize:30]];
//背景色
[button setBackgroundColor:[UIColor redColor]];

//画面に追加
[self.view addSubview:button];

枠線の設定

枠線の色は setBorderColor 、枠線の太さは setBorderWidth 、角丸の丸みは setCornerRadius 、 で指定するができます。

READ MORE

goプロジェクトを自動でUML図に出力するツール

go言語のプロジェクトを可視化したいと思いPlantUMLで自動で出来たらなと。

2つ見つけました。

goplantumlgoumlです。

前者のgoplantumlは、 結構有名でよく紹介されており、メンテが数ヶ月前にされているようです。

後者のgoumlと言うものですが、数年前から開発がとまっていて、

goのver1.18でコンパイルして実行してみると表示が出来ない部分があったので、

READ MORE

時刻ではまった

時刻ではまった。。。。 文字列をtime型にしてからunixtimeに入れようとしたら、

timeStr := "2022-06-07 09:00:00"
layout := "2006-01-02 15:04:05"
timeData, _ = time.Parse(layout, timeStr)
fmt.Println(timeData.Unix()) # => 1654592400

タイムゾーンが、日本に設定してないので、UTCになっているみたい。 time.Parseを使用せずに、locationを設定できるtime.ParseInLocationを使用するとうまく行く。

READ MORE