This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| beforeUnmount() { | |
| console.log("I'm beforeUnmount hook"); | |
| this.$refs.img.width = 0; | |
| }, | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| unmounted() { | |
| console.log("I'm unmounted hook"); | |
| this.$refs.img.width = 0; | |
| }, | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template> | |
| <div ref="greeting">Hello readers !</div> | |
| <img ref="img" :src="img" alt="image" width="200" /> | |
| <span>comment/uncomment me to see beforeUpdate/updated hook's reactivity</span> | |
| </template> | |
| <script> | |
| export default { | |
| setup() { | |
| console.log("I'm setup hook"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1. // check whether element exists in an array | |
| function checkIndexOf() { | |
| let emojis:string[] = ['😎️', '🤓️', '🤩️', '😇️'] | |
| console.log(emojis.indexOf('🤩️') !== -1) | |
| } | |
| // output: | |
| true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func AddDays(t time.Time, days int) time.Time { | |
| fmt.Println("currentTime: ", t) | |
| // AddDate(years int, months int, days int) | |
| newTime := t.AddDate(0, 0, days) | |
| fmt.Println("newTime: ", newTime) | |
| return newTime | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func StartOfDay(t time.Time, timezone string) time.Time { | |
| location, _ := time.LoadLocation(timezone) | |
| year, month, day := t.In(location).Date() | |
| fmt.Println("currentTime: ", t) | |
| dayStartTime := time.Date(year, month, day, 0, 0, 0, 0, location) | |
| fmt.Println("StartOfDay: ", dayStartTime) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func EndOfDay(t time.Time, timezone string) time.Time { | |
| location, _ := time.LoadLocation(timezone) | |
| year, month, day := t.In(location).Date() | |
| fmt.Println("currentTime: ", t) | |
| dayEndTime := time.Date(year, month, day, 23, 59, 59, 0, location) | |
| fmt.Println("EndOfDay: ", dayEndTime) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func IsSameDay(first time.Time, second time.Time) bool { | |
| return first.YearDay() == second.YearDay() && first.Year() == second.Year() | |
| } | |
| /* Check if given two days are same */ | |
| func main() { | |
| location, _ := time.LoadLocation("Asia/Kolkata") | |
| first := time.Date(2022, time.July, 01, 12, 30, 20, 0, location) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func DiffInDays(start time.Time, end time.Time) int { | |
| return int(end.Sub(start).Hours() / 24) | |
| } | |
| /* difference between two timestamps */ | |
| func main() { | |
| location, _ := time.LoadLocation("Asia/Kolkata") | |
| start := time.Date(2022, time.July, 01, 12, 30, 20, 0, location) | |
| end := time.Date(2022, time.July, 31, 15, 0, 50, 0, location) | |
| fmt.Println("Days between start and end: ", DiffInDays(start, end)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func IsLeapYear(year int) bool { | |
| return year%4 == 0 && year%100 != 0 || year%400 == 0 | |
| } | |
| /* check for leap year */ | |
| fmt.Println("2020 is leap year: ", IsLeapYear(2020)) | |
| //output: |