I am quite new in elm and I am trying to create an admin panel that shows the technical support list and their available time according to their local time and their working hours.
Supporter List:
init flags =
( { supportUserList =
[ { supportName = "Maynard Kaminski"
, numberOfClient = 12
, zone = "Europe/Moscow"
, startTime = "9 am"
, endTime = "1 pm"
}
, { supportName = "Belle Willett"
, numberOfClient = 8
, zone = "Canada/Eastern"
, startTime = "2 pm"
, endTime = "6 pm"
}
, { supportName = "Gaylene Hickson"
, numberOfClient = 7
, zone = "Africa/Nairobi"
, startTime = "6 pm"
, endTime = "10 pm"
}
, { supportName = "Cinthia Talbert"
, numberOfClient = 4
, zone = "Asia/Tokyo"
, startTime = "2 pm"
, endTime = "6 pm"
}
, { supportName = "Sydney Crenshaw"
, numberOfClient = 7
, zone = "Pacific/Honolulu"
, startTime = "6 am"
, endTime = "10 am"
}
]
}
, Cmd.none
)
viewSupporter : Supporter -> Html msg
viewSupporter supporter =
li []
[ text supporter.supportName
, text " "
, text " ("
, text (String.fromInt (supporter.numberOfClient))
, text ")"
, text " "
, text supporter.startTime
, text " - "
, text supporter.endTime
, text " ("
, text "local time ?"
, text ")"
]
Expected Result
enter image description here
Current Result
enter image description here
I was trying to check https://guide.elm-lang.org/effects/time.html and How do I get the current time in Elm?
But still could not find a solution.
Here is my current code is in Eillie.
Spent almost 9 hours and could not find a solution. How could I get a person's local time by their time zone value. Thanks
You'll want to convert those zone strings into actual Time.Zones, which can be done with justinmimbs' TimeZone library.
Then, you'll need to get the current time with something like Time.every, and convert it to local parts with Time.Extra.posixToParts.
Some example code:
module Main exposing (main)
import Browser
import Dict
import Html exposing (Html, li, text, ul)
import Time exposing (Month(..))
import Time.Extra
import TimeZone
type Msg
= Tick Time.Posix
type alias Model =
{ now : Time.Posix }
type alias RawSupporter =
{ supportName : String
, numberOfClient : Int
, zone : String
, startTime : String
, endTime : String
}
type alias Supporter =
{ supportName : String
, numberOfClient : Int
, zone : Maybe Time.Zone
, rawZone : String
, startTime : String
, endTime : String
}
rawSupporters : List RawSupporter
rawSupporters =
[ { supportName = "Maynard Kaminski"
, numberOfClient = 12
, zone = "Europe/Moscow"
, startTime = "9 am"
, endTime = "1 pm"
}
, { supportName = "Belle Willett"
, numberOfClient = 8
, zone = "Canada/Eastern"
, startTime = "2 pm"
, endTime = "6 pm"
}
, { supportName = "Gaylene Hickson"
, numberOfClient = 7
, zone = "Africa/Nairobi"
, startTime = "6 pm"
, endTime = "10 pm"
}
, { supportName = "Cinthia Talbert"
, numberOfClient = 4
, zone = "Asia/Tokyo"
, startTime = "2 pm"
, endTime = "6 pm"
}
, { supportName = "Sydney Crenshaw"
, numberOfClient = 7
, zone = "Pacific/Honolulu"
, startTime = "6 am"
, endTime = "10 am"
}
]
supporters : List Supporter
supporters =
rawSupporters
|> List.map
(\raw ->
{ supportName = raw.supportName
, numberOfClient = raw.numberOfClient
, zone =
TimeZone.zones
|> Dict.get raw.zone
|> Maybe.map (\evaluate -> evaluate ())
, rawZone = raw.zone
, startTime = raw.startTime
, endTime = raw.endTime
}
)
viewSupporter : Time.Posix -> Supporter -> Html msg
viewSupporter now supporter =
let
parts =
supporter.zone
|> Maybe.map
(\zone ->
Time.Extra.posixToParts zone now
)
localTimeDisplay =
case parts of
Just { year, month, day, hour, minute, second, millisecond } ->
([ [ year, monthNum month, day ]
|> List.map String.fromInt
|> String.join "-"
, [ hour, minute, second ]
|> List.map String.fromInt
|> String.join ":"
]
|> String.join " "
)
++ " (local time)"
Nothing ->
"<Not a valid timezone: '" ++ supporter.rawZone ++ "'>"
in
[ supporter.supportName
, " ("
, String.fromInt supporter.numberOfClient
, ") "
, supporter.startTime
, " - "
, supporter.endTime
, " "
, localTimeDisplay
]
|> List.map text
|> li []
monthNum : Month -> Int
monthNum m =
case m of
Jan ->
1
Feb ->
2
Mar ->
3
Apr ->
4
May ->
5
Jun ->
6
Jul ->
7
Aug ->
8
Sep ->
9
Oct ->
10
Nov ->
11
Dec ->
12
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Tick newTime ->
( { model | now = newTime }, Cmd.none )
view : Model -> Html Msg
view model =
supporters
|> List.map (viewSupporter model.now)
|> ul []
main : Program () Model Msg
main =
Browser.element
{ init = \() -> ( { now = Time.millisToPosix 0 }, Cmd.none )
, view = view
, update = update
, subscriptions = \_ -> Time.every 1000 Tick
}
Here's the same code running on ellie-app.com.
Related
In the code below ( which is part of a function with = task{ )
Breakpoint 3 is being hit - and breakpoint 1 and 2 are not. the code is working ( i.e. the code is running in the Array.map and produces 29 rows but I can no longer debug that part of the code ). They were breakking and then they just stopped all of a sudden. Tried resetting settings, rebooting machine etc. Any ideas? All the builds are debug / Any CPU
let rows =
data.Rows
|> Seq.toArray
|> Array.map(fun row ->
let transactionDateString = row[0] + " " + row[1] //Breakpoint 1
let ttt = TimeZoneInfo.ConvertTime(DateTime.Parse(transactionDateString, CultureInfo.CreateSpecificCulture("en-AU")),TimeZoneInfo.FindSystemTimeZoneById("E. Australia Standard Time"),TimeZoneInfo.Local)
let transactionDateTime = DateTime.ParseExact(transactionDateString, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture).AddHours(2)
let ttt2 = ttt.ToLocalTime()
let transactionNumber = row.Columns[2].ToString() // [ "TRXN Reference-Eway"]
let t2 = int transactionNumber // Breakpoint 2
let transactionType = row[3].ToString()
let transactionCurrency = currency
let csvData: EwayCSVData = {
transactionDateTime = transactionDateTime
transactionNumber = transactionNumber
transactionType = transactionType
currency = transactionCurrency
}
csvData)
do! EwayTransactions.saveTransactions(rows,sTransCollection, httpClient) // Breakpoint 3
Cannot use 'bgcolor' in local scope
my code :
//#version=4
//strategy("try 2", overlay=true)
study("Astrolog 2", "Astrolog 2", overlay=true)
yearStart = 2015
yearEnd = 2021
for counter = yearStart to yearEnd [1]
i_startTime = input(defval = timestamp("23 Aug 2020 00:00 +0000"), title = "Start Time", type = input.time)
i_endTime = input(defval = timestamp("22 Sep 2020 23:59 +0000"), title = "End Time", type = input.time)
i_length = input(defval = 20, title = "Length", type = input.integer)
inDateRange = time >= i_startTime and time <= i_endTime
bgcolor(inDateRange ? color.green : na, 50)
break
I want every 23 Aug - 22 sept have background color
yearStart = input(2015)
monthStart = input(8)
dayStart = input(23)
yearEnd = input(2021)
monthEnd = input(9)
dayEnd = input(22)
inDayMonthRange = time >= timestamp(year, monthStart, dayStart, 0, 0) and time <= timestamp(year, monthEnd, dayEnd, 0, 0)
inYearRange = year >= yearStart and year <= yearEnd
inRange = inDayMonthRange and inYearRange
bgcolor(inRange ? color.green : na, 50)
You don't need to use a loop, pine's execution model executes the script progressively through each historical bar.
year returns each bar's year portion of the timestamp. So as the script progresses through each historical bar, you can test separately if we are in the day/month range, and then also test if it is in your range of years.
I'm trying to do a search through a table via LINQ and Entity Framework CORE. I've got 2 text boxes startdate and enddate and a radio button set of 3 options created, modified and both.
This is the code I've produced based on Google searches and tutorials
switch(radCreatedModifiedBoth) {
case "b":
if (!String.IsNullOrEmpty(startDate)) {
if (!String.IsNullOrEmpty(endDate)) {
persons = persons.Where(ps => (
ps.CreatedDate >= Convert.ToDateTime(startDate + " 00:00:00") &&
ps.CreatedDate <= Convert.ToDateTime(endDate + " 23:59:59")
) || (
ps.ModifiedDate >= Convert.ToDateTime(startDate + " 00:00:00") &&
ps.ModifiedDate <= Convert.ToDateTime(endDate + " 23:59:59")
)
);
} else {
persons = persons.Where(ps => (
ps.CreatedDate >= Convert.ToDateTime(startDate + " 00:00:00")
||
ps.ModifiedDate >= Convert.ToDateTime(startDate + " 00:00:00")
)
);
}
} else if (!String.IsNullOrEmpty(endDate)) {
persons = persons.Where(ps => (
ps.CreatedDate >= Convert.ToDateTime(endDate + " 23:59:59")
||
ps.ModifiedDate >= Convert.ToDateTime(endDate + " 23:59:59")
)
);
}
break;
case "c":
if (!String.IsNullOrEmpty(startDate)) {
if (!String.IsNullOrEmpty(endDate)) {
persons = persons.Where(ps => (
ps.CreatedDate >= Convert.ToDateTime(startDate + " 00:00:00") &&
ps.CreatedDate <= Convert.ToDateTime(endDate + " 23:59:59")
)
);
} else {
persons = persons.Where(ps => (
ps.CreatedDate >= Convert.ToDateTime(startDate + " 00:00:00")
)
);
}
} else if (!String.IsNullOrEmpty(endDate)) {
persons = persons.Where(ps <= (
ps.CreatedDate >= Convert.ToDateTime(endDate + " 23:59:59")
)
);
}
break;
case "m":
if (!String.IsNullOrEmpty(startDate)) {
if (!String.IsNullOrEmpty(endDate)) {
persons = persons.Where(ps => (
ps.ModifiedDate >= Convert.ToDateTime(startDate + " 00:00:00") &&
ps.ModifiedDate <= Convert.ToDateTime(endDate + " 23:59:59")
)
);
} else {
persons = persons.Where(ps => (
ps.ModifiedDate >= Convert.ToDateTime(startDate + " 00:00:00")
)
);
}
} else if (!String.IsNullOrEmpty(endDate)) {
persons = persons.Where(ps <= (
ps.ModifiedDate >= Convert.ToDateTime(endDate + " 23:59:59")
)
);
}
break;
}
This code works but seems massively inefficient, not to mention adding the start and end time into the date as a string like this
startDate + " 00:00:00"
endDate + " 23:59:59"
just seems wrong. Is this the prescribed method or can anyone suggest a more efficient method preferably getting rid of the " 00:00:00"/" 23:59:59"
Thanks
You can simplify by pushing the tests to SQL - the conditional operator will be translated to SQL CASE WHEN since they aren't simple constants. Note that I assumed you have the endDate tests backwards in your code sample. Also you have a lot of repeated sub-expressions I consolidated to variables. Since you are using EF Core, there isn't a better way to handle date only comparisons then what you are using. In EF you can use a DbFunction, but it still isn't as good as converting your dates to the appropriate date+time so that indices can be used.
var hasStartDate = !String.IsNullOrEmpty(startDate);
var dtStartDate = hasStartDate ? Convert.ToDateTime(startDate + " 00:00:00") : DateTime.MinValue;
var hasEndDate = !String.IsNullOrEmpty(endDate);
var dtEndDate = hasEndDate ? Convert.ToDateTime(endDate + " 23:59:59") : DateTime.MinValue;
var chkCreatedDate = (radCreatedModifiedBoth == "b" || radCreatedModifiedBoth == "c");
var chkModifiedDate = (radCreatedModifiedBoth == "b" || radCreatedModifiedBoth == "m");
persons = persons.Where(ps => (chkCreatedDate ? (hasStartDate ? ps.CreatedDate >= dtStartDate : true) && (hasEndDate ? ps.CreatedDate <= dtEndDate : true) : true)
||
(chkModifiedDate ? (hasEndDate ? ps.ModifiedDate >= dtStartDate : true) && (hasEndDate ? ps.ModifiedDate <= dtEndDate : true) : true)
);
In FileMaker Pro, I am trying to append the current date and time to a filename to which I export data. If I use
Get (CurrentTime)
I get 12-hour time, complete with " PM" or " AM" at the end. Is there built-in functionality to return 24-hour time, instead?
FileMaker help says that the format follows the format of system time, but that is not the case. System time is showing as 17:22, but CurrentTime is returning 52218 PM. (Mac OS 10.8.5, FileMaker Pro 12.0v4.)
Filemaker's internal time storage notation is simply the number of seconds elapsed since midnight of the current day.
I.e. 56659 seconds since midnight = 3:44:19 PM.
When exporting data, you can check off the "Apply current layout's data formatting to exported data" checkbox, so that times displayed as 24-hour in FMP layouts are exported as such.
But, for other internal use such as the file-naming case you're asking about, you will need to use a custom function to convert the output of Get(currentTime) to 24-hour format.
For example, see the TimeFormatAs ( theTime ; type12or24 ) function at Briandunning.com.
(Full code of the custom function is pasted below for protection against dead links in the future, but if the link above still works, use that version as it may be more up-to-date:)
/*---------------------------------------------------------------
Function Name: TimeFormatAs
Syntax: TimeFormatAs ( theTime; type12or24 )
Author - Jonathan Mickelson, Thought Development Corp.
(www.thought-dev.com)
---------------------------------------------------------------*/
Case ( not IsEmpty ( theTime ) ;
Let (
[
// FIXED VARIABLES
padHoursChar = "" ; // Character to pad the Hours with in a text result, (Ex."0", " ", "")
padAMPMChar = " " ; // Character to pad the AM/PM with in a text result, (Ex."0", " ", "")
suffixAM = "AM" ; // <------------ CHANGE AM Suffix Here
suffixPM = "PM" ; // <------------ CHANGE PM Suffix Here
// DYN. VARIABLES
theTime = GetAsTime ( theTime ) ;
hasSeconds = PatternCount ( GetAsText ( theTime ) ; ":" ) = 2 ;
secs = Mod ( Seconds ( theTime ) ; 60 ) ;
mins = Mod ( Minute ( theTime ) ; 60 ) + Div ( Seconds ( theTime ) ; 60 ) ;
hours = Hour ( theTime ) + Div ( Minute ( theTime ) ; 60 ) ;
// -------------- BEGIN 24 HOUR TIME CALC ----------------------
result24 = GetAsTime ( theTime ) + 1 - 1 ;
// -------------- BEGIN 12 HOUR TIME CALC ----------------------
hours = Mod ( Hour ( theTime ) ; 12 ) ;
tempHours = Case ( ( hours < 1 ) or ( hours - 12 = 0 ) ; 12 ; hours ) ;
calc12Hours =
Left (
padHoursChar & padHoursChar ;
2 - Length ( tempHours )
) &
tempHours ;
calc12Minutes = Left ( "00" ; 2 - Length ( mins ) ) & mins ;
calc12Seconds = Left ( "00" ; 2 - Length ( secs ) ) & secs ;
calc12Suffix = Case ( Mod ( Hour ( theTime ) ; 24 ) >= 12 ; suffixPM ; suffixAM ) ;
result12 = calc12Hours &
":" & calc12Minutes &
// if original time included a non-zero seconds value, display seconds
Case ( hasSeconds and secs > 0 ; ":" & calc12Seconds ) &
padAMPMChar & calc12Suffix
] ;
Case ( type12or24 >= "24" ; result24 ; result12 ) // END CASE
) // END LET
) // END CASE
I have StartDate (for instance 2011-01-01) and EndDate (for instance 2011-12-31).
All my data are placed in this range.
In test plan I need to generate random interval with fixed duration
(for 4 cases: 1, 3, 7 days and 1 month long)
which are placed in this date range [2011-01-01; 2011-12-31].
Each of these cases must have defined weights.
How should I do to get fixed interval with random Start Date and random End Date (and put these random dates into 2 variables)?
I have found this variant of java-script
The initial script is here:
var startDate = new Date();
startDate.setDate(1);
startDate.setMonth(0);
startDate.setYear(1991);
var startDateTime = startDate.getTime();
var endDate = new Date();
endDate.setDate(31);
endDate.setMonth(11);
endDate.setYear(2003);
var endDateTime = endDate.getTime();
var randomDate = new Date();
var randomDateTime = startDateTime+Math.random()*(endDateTime-startDateTime);
randomDate.setTime(randomDateTime);
var rndDate = randomDate.getDate();
var rndMonth = randomDate.getMonth() + 1;
var rndYear = randomDate.getFullYear();
if (rndDate.toString().length == 1)
rndDate = "0" + rndDate;
if (rndMonth.toString().length == 1)
rndMonth = "0" + rndMonth;
rndDate + "/" + rndMonth + "/" + rndYear;
But I need generate random start date of the fixed interval (which I called ${RandomStartDate}) and then to add the length of the interval to get the end date of it (this date I called ${RandomEndDate}).
Then I have change the script for 1 day long interval (1 day is 86400 seconds):
var startDate = new Date();
startDate.setDate(01);
startDate.setMonth(01);
startDate.setYear(2011);
var startDateTime = startDate.getTime();
var endDate = new Date();
endDate.setDate(31);
endDate.setMonth(12);
endDate.setYear(2011);
var endDateTime = endDate.getTime();
var randomSDate = new Date();
var randomSDateTime = startDateTime+Math.random()*((endDateTime - 86400) -startDateTime );
randomSDate.setTime(randomSDateTime);
var randomEDate = new Date();
var randomEDateTime = (randomSDateTime + 86400); //add 1 day long interval (86400 s)
randomEDate.setTime(randomEDateTime); //convert number format to string format of date
var rndSDate = randomSDate.getDate();
var rndSMonth = randomSDate.getMonth()+1 ;
var rndSYear = randomSDate.getFullYear();
var rndEDate = randomEDate.getDate();
var rndEMonth = randomEDate.getMonth()+1 ;
var rndEYear = randomEDate.getFullYear();
if (rndSDate.toString().length == 1)
rndSDate = "0" + rndSDate;
if (rndSMonth.toString().length == 1)
rndSMonth = "0" + rndSMonth;
if (rndEDate.toString().length == 1)
rndEDate = "0" + rndEDate;
if (rndEMonth.toString().length == 1)
rndEMonth = "0" + rndEMonth;
var RandomStartDate = rndSYear + "-" + rndSMonth + "-" + rndSDate;
vars.put ("RandomStartDate", RandomStartDate);
var RandomEndDate = rndEYear + "-" + rndEMonth + "-" + rndEDate;
vars.put ("RandomEndDate", RandomEndDate);
But this script generates RandomEndDate which is equal to RandomStartDate.
If I generate RandomStartDate separately (without the parts of code which are connected with RandomEndDate) the script works good.
Could you help me, please? What is wrong?
You can do it in Beanshell with much less amount of code:
import java.text.SimpleDateFormat;
import java.util.Calendar;
calendar = Calendar.getInstance();
calendar.set(2011, 0, 1);
startTime = calendar.getTimeInMillis();
calendar.set(2012, 11, 31);
endTime = calendar.getTimeInMillis();
randomTime1 = startTime + (long)(Math.random()*(endTime-startTime));
randomTime2 = randomTime1 + (long)(Math.random()*(endTime - randomTime1)+86400000);
formatter = new SimpleDateFormat("yyyy-MM-dd");
calendar.setTimeInMillis(randomTime1);
vars.put("start", formatter.format(calendar.getTime()));
calendar.setTimeInMillis(randomTime2);
vars.put("end", formatter.format(calendar.getTime()));
For situations like this I would opt to put the complexity outside of jMeter, and create a perl script to generate 100 pairs of dates according to your requirements and read them into jMeter variables using CSV Data Set Config.
I have found the solution!
This is the correct script, which allow to model the random interval with fixed length (1 day long interval) and get 2 variables fot it start and end - ${RandomStartDate} and ${RandomEndDate}:
var startDate = new Date();
startDate.setDate(01);
startDate.setMonth(01);
startDate.setYear(2011);
var startDateTime = startDate.getTime();
var endDate = new Date();
endDate.setDate(31);
endDate.setMonth(12);
endDate.setYear(2011);
var endDateTime = endDate.getTime();
var randomSDate = new Date();
var randomSDateTime = startDateTime+Math.random()*((endDateTime - 86400000) -startDateTime );
randomSDate.setTime(randomSDateTime);
var randomEDate = new Date();
var randomEDateTime = (randomSDateTime + 86400000); //add 1 day long interval (86400000 ms)
randomEDate.setTime(randomEDateTime); //convert number format to string format of date
var rndSDate = randomSDate.getDate();
var rndSMonth = randomSDate.getMonth()+1 ;
var rndSYear = randomSDate.getFullYear();
var rndEDate = randomEDate.getDate();
var rndEMonth = randomEDate.getMonth()+1 ;
var rndEYear = randomEDate.getFullYear();
if (rndSDate.toString().length == 1)
rndSDate = "0" + rndSDate;
if (rndSMonth.toString().length == 1)
rndSMonth = "0" + rndSMonth;
if (rndEDate.toString().length == 1)
rndEDate = "0" + rndEDate;
if (rndEMonth.toString().length == 1)
rndEMonth = "0" + rndEMonth;
var RandomStartDate = rndSYear + "-" + rndSMonth + "-" + rndSDate;
vars.put ("RandomStartDate", RandomStartDate);
var RandomEndDate = rndEYear + "-" + rndEMonth + "-" + rndEDate;
vars.put ("RandomEndDate", RandomEndDate);
My mistake was I thought that the time is in seconds, but it is in milliseconds!