DateTime structure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paulers

    #1

    DateTime structure

    Hello

    Is it possible to create a DateTime structure that does not include the
    date? I am only intrested in the time and day. for example 23:00 Mon. I
    would eventually like to add and subtract hours to based on a UTC
    calculation.

    any help is greatly appreciated.

  • Paulers

    #2
    Re: DateTime structure

    Arrrrgg!!! this is so frustrating.

    I am trying the following

    Dim MyTime As System.DateTime
    MyTime = System.DateTime .Parse("8:00 mon")
    MyTime = MyTime.AddHours (-11)
    MyTime = MyTime.AddHours (-5)
    MsgBox(MyTime.T oString("HH:mm ddd"))

    but it only works on the day equivelant to today, in this case monday..
    If I plug in 8:00 Tue through sun it errors. Is there any way to
    accomplish this? It seems to still be bound to a date. I am trying to
    convert a shift schedule from Sydney time, to Eastern. I do not care
    about the date, just the day ranges and hours.

    Is there any way to do this?

    Comment

    • Stephany Young

      #3
      Re: DateTime structure

      I think that, for this exercise, because the date is irrelevant, you need to
      create your own class that does some number crunching without using DateTime
      structures at all.

      Using the example you have given, it might be something like:

      Public Class MyScheduleItem

      Public Shared Function ConvertLocalToR emote(ByVal LocalTimeOfDay As
      Integer, ByVal LocalDayOfWeek As DayOfWeek, ByVal RemoteOffset As Integer)
      As String

      Dim _RemoteTimeOfDa y As Integer = LocalTimeOfDay + RemoteOffset

      Dim _RemoteDayOfWee k As DayOfWeek = LocalDayOfWeek

      Select Case _RemoteTimeOfDa y
      Case < 0
      _RemoteDayOfWee k = CType(Convert.T oInt32(_RemoteD ayOfWeek) - 1,
      DayOfWeek)
      _RemoteTimeOfDa y = 1440 + _RemoteTimeOfDa y
      Case >= 1440
      _RemoteDayOfWee k = CType(Convert.T oInt32(_RemoteD ayOfWeek) + 1,
      DayOfWeek)
      End Select

      Select case _RemoteDayOfWee k
      Case < DayOfWeek.Sunda y
      _RemoteDayOfWee k = DayOfWeek.Satur day
      Case > DayOfWeek.Satur day
      _RemoteDayOfWee k = DayOfWeek.Sunda y
      End Select

      Return String.Format(" {0:#0}:{1:00} {2}", Fix(_RemoteTime OfDay \ 60) ,
      _RemoteTimeOfDa y Mod 60, _RemoteDayOfWee k.ToString.SubS tring(0,3))

      End Sub

      End Class

      Note that LocalTimeOfDay, _RemoteTimeOfDa y and RemoteOffset are in units of
      minutes thus handling times of day and offsets that are not whole hours.

      Note also that the week is deemed to run from Sunday (0) to Saturday (6).

      Call it with:

      Console.WriteLi ne(MyScheduleIt em.ConvertLocal ToRemote(8 * 60,
      DayOfWeek.Monda y, -(16 * 60)))

      Dissect it to your hearts content to see how it works and improve on it.


      "Paulers" <SuperGh0d@gmai l.com> wrote in message
      news:1139885729 .828315.196990@ g14g2000cwa.goo glegroups.com.. .[color=blue]
      > Arrrrgg!!! this is so frustrating.
      >
      > I am trying the following
      >
      > Dim MyTime As System.DateTime
      > MyTime = System.DateTime .Parse("8:00 mon")
      > MyTime = MyTime.AddHours (-11)
      > MyTime = MyTime.AddHours (-5)
      > MsgBox(MyTime.T oString("HH:mm ddd"))
      >
      > but it only works on the day equivelant to today, in this case monday..
      > If I plug in 8:00 Tue through sun it errors. Is there any way to
      > accomplish this? It seems to still be bound to a date. I am trying to
      > convert a shift schedule from Sydney time, to Eastern. I do not care
      > about the date, just the day ranges and hours.
      >
      > Is there any way to do this?
      >[/color]


      Comment

      Working...