September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -10,6 +10,6 @@ The bell timing should be in accordance with [[wp:GMT|Greenwich Mean Time]], unl
|
|||
It is permissible for the program to [[Run as a daemon or service|daemonize]], or to slave off a scheduler, and it is permissible to use alternative notification methods (such as producing a written notice "Two Bells Gone"), if these are more usual for the system type.
|
||||
|
||||
|
||||
;Cf.:
|
||||
;Related task:
|
||||
* [[Sleep]]
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
---
|
||||
category:
|
||||
- Date and time
|
||||
35
Task/Nautical-bell/C/nautical-bell.c
Normal file
35
Task/Nautical-bell/C/nautical-bell.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include<unistd.h>
|
||||
#include<stdio.h>
|
||||
#include<time.h>
|
||||
|
||||
#define DELAY 3000
|
||||
|
||||
int main(){
|
||||
int i,times;
|
||||
|
||||
time_t t;
|
||||
struct tm* currentTime;
|
||||
|
||||
while(1){
|
||||
time(&t);
|
||||
currentTime = localtime(&t);
|
||||
|
||||
times = (currentTime->tm_hour%12==0)?12:currentTime->tm_hour%12;
|
||||
|
||||
if(currentTime->tm_min==0 && currentTime->tm_sec==0){
|
||||
printf("\nIt is now %d:00 %s. Sounding the bell %d times.",times,(currentTime->tm_hour>11)?"PM":"AM",times);
|
||||
|
||||
for(i=0;i<times;i++){
|
||||
printf("\a");
|
||||
sleep(DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
else if(currentTime->tm_min==30 && currentTime->tm_sec==0){
|
||||
printf("\nIt is now %d:30 %s. Sounding the bell once.",times,(currentTime->tm_hour>11)?"PM":"AM");
|
||||
printf("\a");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
54
Task/Nautical-bell/Kotlin/nautical-bell.kotlin
Normal file
54
Task/Nautical-bell/Kotlin/nautical-bell.kotlin
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// version 1.1.3
|
||||
|
||||
import java.text.DateFormat
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.TimeZone
|
||||
|
||||
class NauticalBell: Thread() {
|
||||
|
||||
override fun run() {
|
||||
val sdf = SimpleDateFormat("HH:mm:ss")
|
||||
sdf.timeZone = TimeZone.getTimeZone("UTC")
|
||||
var numBells = 0
|
||||
var time = System.currentTimeMillis()
|
||||
var next = time - (time % (24 * 60 * 60 * 1000)) // midnight
|
||||
|
||||
while (next < time) {
|
||||
next += 30 * 60 * 1000 // 30 minutes
|
||||
numBells = 1 + (numBells % 8)
|
||||
}
|
||||
|
||||
while (true) {
|
||||
var wait = 100L
|
||||
time = System.currentTimeMillis()
|
||||
if ((time - next) >= 0) {
|
||||
val bells = if (numBells == 1) "bell" else "bells"
|
||||
val timeString = sdf.format(time)
|
||||
println("%s : %d %s".format(timeString, numBells, bells))
|
||||
next += 30 * 60 * 1000
|
||||
wait = next - time
|
||||
numBells = 1 + (numBells % 8)
|
||||
}
|
||||
try {
|
||||
Thread.sleep(wait)
|
||||
}
|
||||
catch (ie: InterruptedException) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val bells = NauticalBell()
|
||||
with (bells) {
|
||||
setDaemon(true)
|
||||
start()
|
||||
try {
|
||||
join()
|
||||
}
|
||||
catch (ie: InterruptedException) {
|
||||
println(ie.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue