Jump to content

[solved] Time of Day


Recommended Posts

OK so looks like i missed school a bit as i seem to remember getting these kind of projects to do, only then it was in Ada, which for those that don't know understood fuzzy logic.

I'm looking for a fuzzy way to do time, e.g.

00:00 to 06:59 is too dam early

07:00 to 11:59 is morning

12:00 to 17:59 is afternoon

18:00 to 23:50 is evening

While I can think of several ways to do it they all seem to involve lots of case or if statements, I have not really fully understood the operators yet == <= >= etc. maybe I could use them more effectively, or would a better way be to use an array?

Any pointers would be nice, I don't want to re-invent the wheel if possible.

Edited by PeterAtkin

[topic='115020'] AD Domain Logon Script[/topic]

Link to comment
Share on other sites

  • Moderators

PeterAtkin,

lots of case or if statements

Surely not: :mellow:

Switch @HOUR
    Case 0 To 6
        ConsoleWrite("Too damn early!" & @CRLF)
    Case 7 To 11
        ConsoleWrite("Morning" & @CRLF)
    Case 12 To 17
        ConsoleWrite("Afternoon" & @CRLF)
    Case Else
        ConsoleWrite("Evening" & @CRLF)
EndSwitch

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

_TimeToWords("3:45")
_TimeToWords("13:15")
_TimeToWords("23:05")
_TimeToWords("00:05")

Func _TimeToWords($time)
    Switch StringRegExpReplace($time, ':.*', '')
        Case 00 To 06
            ConsoleWrite('is too dam early' & @CRLF)
        Case 07 To 11
            ConsoleWrite('is morning' & @CRLF)
        Case 12 To 17
            ConsoleWrite('is afternoon' & @CRLF)
        Case 18 To 23
            ConsoleWrite('is evening' & @CRLF)
    EndSwitch
EndFunc ;==>_TimeToWords

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

I'm looking for a fuzzy way to do time, e.g.

00:00 to 06:59 is too dam early

07:00 to 11:59 is morning

12:00 to 17:59 is afternoon

18:00 to 23:50 is evening

Only thing I can think of would be something like this:

Func fuzzyTime ($Time)
    If $Time < 7 Then
        Return "is too early"
    Elseif $Time < 12 Then
            Return "is morning"
    Elseif $Time < 18 Then
            Return "is afternoon"
    EndIf
    Return "is evening"
EndFunc

Feed @Hour to that and it should return what you are looking for.

Edit: Cleaned up the look of the code. Wow, that was a race to be first :mellow:

Edited by Fulano

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

Excellent thanks I was really going about this the wrong way.. just so you can have a laugh Posted Image

local $greeting

switch @HOUR
Case 1
  $greeting = "this is just too early"
Case 2
  $greeting = "this is just too early"
Case 3
  $greeting = "this is just too early"
Case 4
  $greeting = "this is just too early"
Case 5
  $greeting = "this is just too early"
Case 6
  $greeting = "this is just too early"
Case 7
  $greeting = "Good Morning"
Case 8
  $greeting = "Good Morning"
Case 9
  $greeting = "Good Morning"
Case 10
  $greeting = "Good Morning"
Case 11
  $greeting = "Good Morning"
Case 12
  $greeting = "Good Afternoon"
Case 13
  $greeting = "Good Afternoon"
Case 14
  $greeting = "Good Afternoon"
Case 15
  $greeting = "Good Afternoon"
Case 16
  $greeting = "Good Afternoon"
Case 17
  $greeting = "Good Afternoon"
Case 18
  $greeting = "Good Afternoon"
Case 19
  $greeting = "Good Evening"
Case 20
  $greeting = "Good Evening"
Case 21
  $greeting = "Good Evening"
Case 22
  $greeting = "Good Evening"
Case 23
  $greeting = "This is way too late"
Case 00
  $greeting = "Goto Bed"
EndSwitch

_say($greeting & " " & @UserName & " welcome to the Computer Facilities Network, please wait while you are logged onto the system")

Func _say($v2t)
Local $objVoice = False, $temp
$objVoice = ObjCreate("SAPI.SpVoice")
$objVoice.Volume = 50
$objVoice.Rate = 0
$objVoice.Speak($v2t, 0)
EndFunc   ;==>_say

And this is the solution I come up with, with your help.

$greeting = FuzzyTime()
_say($greeting & " " & @UserName & " welcome to the Computer Facilities Network, please wait while you are logged onto the system")

Func FuzzyTime()
Switch @HOUR
Case 0 To 6
  Return "is too early"
Case 7 To 11
  Return "Good Morning"
Case 12 To 17
  Return "Good Afternoon"
Case 18 To 23
  Return "Good Evening"
Case Else
  Return "Go to bed"
EndSwitch
EndFunc

Func _say($v2t)
Local $objVoice = False, $temp
$objVoice = ObjCreate("SAPI.SpVoice")
$objVoice.Volume = 50
$objVoice.Rate = 0
$objVoice.Speak($v2t, 0)
EndFunc   ;==>_say
Edited by PeterAtkin

[topic='115020'] AD Domain Logon Script[/topic]

Link to comment
Share on other sites

  • Moderators

PeterAtkin,

Thanks for that - always nice to get positive feedback (and a good laugh)! :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

As it's a greeting "is too early" doesn't really fit in there. Shouldn't you make it something like "What are you doing here so early, go back to bed!" :mellow:?

Edited by dani
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...