Tabbas, bari mu ฦirฦiri labarin game da mahimmancin kyakkyawan barcin dare da kuma yadda codeing zai iya taimaka mana bincika yanayin barci ta amfani da Typescript.
Barci muhimmin bangare ne na rayuwarmu. Lokaci ne da jikinmu ya sake farfadowa kuma ya gyara, yana shirya mu don kalubalen rana mai zuwa. Duk da haka, mutane da yawa suna fama da matsalar barci ko kuma gwagwarmaya don kula da tsaftar barci. A matsayin masu haษakawa, za mu iya ฦirฦirar aikace-aikace don taimakawa saka idanu da inganta barci.
A cikin wannan labarin, za mu bincika yadda ake gina ainihin ma'aunin barci ta amfani da Typescript da ษakin karatu na Moment.js.
Magani: Mai Kula da Barci
A zamanin yau na wearables da aikace-aikacen wayar hannu, bin diddigin barci kayan aiki ne na kowa don saka idanu da inganta halayen bacci. Za mu iya yin amfani da waษannan fasahohin ta hanyar yin amfani da Typescript, sanannen yaren shirye-shirye, don ฦirฦirar mai kula da barci.
Mai bin diddigin barci zai rubuta lokacin barcin ku da lokacin tashi kuma ya ฦididdige tsawon lokacin barcin ku. Wannan yana ba ku damar saka idanu kowane sabani daga tsarin bacci na yau da kullun kuma ษaukar matakan da suka dace don haษaka tsaftar barcinku.
Bari mu zurfafa cikin yadda za mu iya gina wannan ma'aunin barci ta amfani da Typescript da Moment.js.
Gina Mabiyan Barci
Don gina wannan aikace-aikacen, da farko za mu yi amfani da Typescript, babban saiti na JavaScript, wanda ke ฦara nau'ikan iri a cikin harshe. Nau'ukan tsaye na iya sa lambar mu ta zama abin karantawa da kuma hana yuwuwar kurakuran lokacin aiki. Za mu yi amfani da ษakin karatu na Moment.js don sarrafa kwanan wata da lokaci.
import * as moment from 'moment'; class SleepTracker { private sleepTime: moment.Moment = null; private wakeTime: moment.Moment = null; sleep() { this.sleepTime = moment(); } wake() { this.wakeTime = moment(); } getSleepDuration() { if (this.sleepTime && this.wakeTime) { let duration = moment.duration(this.wakeTime.diff(this.sleepTime)); return `${duration.hours()} hours ${duration.minutes()} minutes`; } return 'You have not slept yet'; } }
Bayyana Code
Ajin SleepTracker yana da hanyoyi uku: barci(), farkawa(), da samun Barci(). Hanyar barci () tana rubuta lokacin da kuka fara barci, kuma hanyar farkawa () tana rubuta lokacin da kuka tashi. Hanyar samunSleepDuration() tana ฦididdige tsawon lokacin barcin ku bisa la'akari da lokutan barci da lokacin farkawa.
Yin amfani da Tracker na Barci
Yin amfani da ma'aunin barci abu ne mai sauฦi. Kafin barci, kira hanyar barci(). Bayan kun tashi, kira hanyar farkawa. Don samun tsawon lokacin barci, kira hanyar samunSleepDuration().
Irin wannan kayan aiki zai iya taimakawa wajen sauฦaฦe tsaftar barci mai kyau da inganta lafiyar jiki da jin dadi. Tare da wasu kayan haษakawa, ana iya ฦarawa don nazarin yanayin barci da bayar da shawarwari.
Barci muhimmin bangare ne na rayuwarmu. A matsayin masu haษakawa, yin amfani da ฦwarewarmu don ฦirฦirar kayan aikin don taimakawa lafiyar barci na iya samun fa'idodi masu mahimmanci fiye da yadda za mu iya fahimta da farko. Bibiyar barci, idan anyi daidai kuma akai-akai, na iya samar da fahimi masu mahimmanci game da halayen barcinmu kuma ya taimaka mana inganta su a cikin dogon lokaci.